Basic NPC Architecture in Roblox
A Roblox NPC is fundamentally a Model with a Humanoid, HumanoidRootPart, and body parts. The Humanoid gives it health, walkspeed, and animation support. The AI logic runs on the server via a Script, not the client. Never run NPC logic on the client — it creates security vulnerabilities and desync issues. The server script controls movement, combat decisions, and state transitions while the client handles visual feedback like animations and health bars.
NPC Pathfinding with PathfindingService
Roblox's PathfindingService computes walkable paths between two points, handling obstacles and terrain. Create a path with PathfindingService:CreatePath(), compute it with Path:ComputeAsync(), then move the NPC along the waypoints using Humanoid:MoveTo(). The key gotcha is that paths can become invalid if the environment changes — recompute the path periodically and handle PathBlocked events. For smooth movement, interpolate between waypoints rather than teleporting to each one.
Combat AI Patterns
Enemy NPCs need decision-making logic for engaging players. The most common patterns are:
- Aggro radius — NPC detects players within a sphere and switches to chase state
- State machine — Idle, Patrol, Chase, Attack, Retreat states with clear transitions
- Attack cooldowns — Prevent NPCs from attacking every frame; use timers between strikes
- Threat tables — Multi-target NPCs track which player has dealt the most damage
- Leash range — NPCs return to spawn if pulled too far, preventing exploit kiting
Boss AI Design
Boss NPCs are more complex than standard enemies. They typically have multiple attack patterns that cycle or phase-shift based on health thresholds. A well-designed boss uses telegraphed attacks (wind-up animations that warn the player), varied timing to prevent rhythm-based cheesing, and environmental mechanics. Building a single boss encounter from scratch can take 40+ hours of development and testing.
Pre-Built NPC Systems Save Weeks
Building a complete NPC system — AI, pathfinding, combat, animations, health bars, spawning, loot drops — from scratch takes weeks for a single developer. Pre-built NPC systems give you battle-tested AI with professional animations, optimized for server performance. KitsBlox NPC packs include fully rigged characters with combat AI, pathfinding, state machines, and all animations pre-configured.
