Pathfinding in Roblox
Navigate NPCs and objects through complex environments using PathfindingService and waypoint systems.
Introduction
PathfindingService calculates optimal routes through your game's geometry, avoiding walls and obstacles. It powers NPC movement, pet following, and automated object delivery. This hub explains path computation, waypoint traversal, and common pitfalls.
Computing a Basic Path
local path = PathfindingService:CreatePath({ AgentRadius = 2, AgentHeight = 5, AgentCanJump = true }). path:ComputeAsync(npc.HumanoidRootPart.Position, targetPosition). if path.Status == Enum.PathStatus.Success then local waypoints = path:GetWaypoints() -- move to each waypoint end
Use Cases
- NPC patrol routes
- Pet follow mechanics
- Delivery missions
Best Practices
- Recalculate when paths are blocked
- Throttle path requests
- Tune agent parameters to model size
Troubleshooting
Script runs but nothing happens in-game
Verify the script type matches its location. Server Scripts belong in ServerScriptService; LocalScripts in StarterPlayerScripts or StarterGui. Check the Output window in Studio for error messages.
Changes don't appear after editing
Stop and restart Play mode in Studio. Some scripts cache values on first run. For published games, republish after testing locally.