Pathfinding Service on Roblox


I have been trying my luck with the pathfinding service , using it to have NPC’s chase players. I notice there is no mention in the documentation regarding using the service for moving targets. It seems it delivers a set of waypoints, not much more. It is left up to us to develop the rest. After coming across several problems, I reduced my trial and error down to an NPC trying to find a stationary object. What I have tried so far

  1. have an NPC find an object in a 5x5 generated maze.
    this works - 103 waypoints were generated and the NPC could find the target

  2. have an NPC find an object in a 10x10 generated maze.
    this works - 324 waypoints were generated

  3. have an NPC find an object in a 20x20 generated maze.
    the pathfinding service breaks down here and returns with a state ‘No Path Found’

My code is taken directly from the documentation:

But here it is again anyways:

local PathfindingService = game:GetService("PathfindingService")

-- Variables for the zombie, its humanoid, and destination
local zombie = game.Workspace.RoblotGold
local humanoid = zombie.Humanoid
local destination = game.Workspace.Destination

-- Create the path object
local path = PathfindingService:CreatePath()

-- Compute the path
path:ComputeAsync(zombie.HumanoidRootPart.Position, destination.Position)

-- Get the path waypoints
local waypoints = path:GetWaypoints()

-- Get the path waypoints
local waypoints = path:GetWaypoints()

--print("here we go. there are this many waypoints : "..#waypoints)

if path.Status == Enum.PathStatus.Success then
	print("path successfully deterimned with "..#waypoints.."  waypoints")
elseif path.Status == Enum.PathStatus.NoPath then
	print("path could not be determined")

-- Loop through waypoints
for _, waypoint in pairs(waypoints) do
	local part ="Part")
	part.Shape = "Ball"
	part.Material = "Neon"
	part.Size =, 0.6, 0.6)
	part.Position = waypoint.Position
	part.Anchored = true
	part.CanCollide = false
	part.Parent = game.Workspace
	-- Move zombie to the next waypoint
	-- Wait until zombie has reached the waypoint before continuing

Is there something I missed or is the roblox pathfinding service really as bad as it seems.

I guess I am looking for hope that I the service actually really fabulous and I have overlooked something by someone pointing out to me how it is supposed to be done.

Thank you.

ps. by the way I have created a video to visualize this:


You could probably do a for loop and repeatedly do pathfinding so that the path changes along with the target

1 Like

I am only testing against a non-moving, stationary target. The service stops delivering when the landscape becomes a bit more challenging

Sorry, I must’ve misread the post

Are you sure there is a possible solution for solving the labyrinth? If yes can you send a picture with it?

here is a picture with a hand drawn out solution. I am also going to attach the project as well in case anyone wants to look at it. thanks

20x20-1a-question-1a.rbxl (208.5 KB)

Have you tried moving where the zombie is pathfinding to? PathfindingService can be weird sometimes in that it just doesn’t register that certain areas exist.

(Also, why do you get the waypoints twice?)

When I opened the place and run it the result was this:

have you put the goal destination twice?

Even correcting for the double destination it doesn’t work. Personally if you’re doing a maze like this I would use A* pathfinding. I feel Roblox’s path finding service is best suited to larger open maps.

1 Like

I have had problems with pathfinding service when I put in agent pathParams it sometimes can’t seem to do seemingly easy paths.

Idk if this would help but if you go to Studio settings and go to Studio tab. Scroll down and then you will see the Pathfinding mesh. If you tick that it will show where a humanoid can and can’t go.

The default pathfinding service sucks imo. Better use A*

I feel it depends on your experience - I’ve got Roblox’s PathFindingService working perfectly. But that’s because my map is terrain (1024*512) and I created invisible barriers to determine cliffs etc.

But for a map that requires a more defined or restricted path (like a maze or dungeons etc) you are better using A*. I’ve amended your code to include an A* script and added some nodes.

20x20-1a-question-1a (a-star).rbxl (212.1 KB)

This seems to work very well (although I didn’t add every node). To continue you’d need the Node Map 2 plugin.


20x20-1a-question-1a.rbxl (90.9 KB)
my bad. I took out the second destination.

1 Like

thanks, copy and paste error. same result and problem though

thank you, I am looking at your new code now and will try it out tomorrow

This is off topic. Please move this to #help-and-feedback:scripting-support. . . .

hi pjhinthehouse, I tried your solution and the project file is working well. the thing is, I am generating a new maze dynamically. I am trying out this node plugin and it seems the nodes are manually laid out ahead of time.

On the other hand I like the A* algorithm and maybe could use that by itsself. I will go back to the drawing board now…

Suggest you automate node creation and connections in a grid and then use A*. You could probably script it to find all nodes in a radius and connect them together.