"Attempt to index nil with 'GetWaypoints'" (Pathfinding)

Hi devs,

For some reason, I get the error “Attempt to index nil with ‘GetWaypoints’” whenever I use this code:

local path = game:GetService("PathfindingService"):CreatePath({AgentWidth = 2, AgentHeight = 5.75, AgentCanJump = false}):ComputeAsync(script.Parent.HumanoidRootPart.Position, nearestPlayer.HumanoidRootPart.Position)
waypoints = path:GetWaypoints()

The HumanoidRootPart’s position for both of the parameters isn’t nil.

ComputeAsync doesn’t return anything
https://developer.roblox.com/en-us/api-reference/function/Path/ComputeAsync

GetWaypoints is a function of Path, so I’d pretty much do

local path = ...:CreatePath({...})
path:ComputeAsync(...)

waypoints = path:GetWaypoints()
1 Like

Thanks, but now the character doesn’t go around walls.
Do you know how I could fix this?
Here’s the code I have:

local path = game:GetService("PathfindingService"):CreatePath({AgentWidth = 2, AgentHeight = 5.75, AgentCanJump = false})
local success, errormsg = pcall(function()
	path:ComputeAsync(script.Parent.HumanoidRootPart.Position, nearestPlayer.HumanoidRootPart.Position)
end)
if success then
	local waypoints = path:GetWaypoints()
	for _, i in waypoints do
		if (waypoints[#waypoints].Position - nearestPlayer.HumanoidRootPart.Position).Magnitude > 5 or not nearestPlayer then
			break
		end
		script.Parent.Humanoid:MoveTo(i.Position)
	end
end

Adding a MoveToFinished:Wait() also doesn’t work.

I’m not sure in that case
MoveToFinished should be firing and idk what else you can use to check when the movement is done

1 Like

I think it might be a problem with the path, rather than a MoveToFinished:Wait() problem.
e
(The circles are the path waypoints)

did you make sure the walls are collidable or has canquery enabled?
also, idk the internals of the pathfinding service, but try again with the walls visible

1 Like

I think the problem must have been that the walls were 0.25 thick, I made them bigger and now the character can go around them…

1 Like