Attempt to index nil with 'GetWaypoints'

Pathfinding doesn’t work, I don’t know why. There’s nothing obstructing it.

Function that pathfinds:

function walkTo(destination)
	local pathParams = {
		["AgentHeight"] = 6.2,
		["AgentRadius"] = 4,
		["AgentCanJump"] = false
	}

	local path = pathfindingService:CreatePath(pathParams)
	
	path = path:ComputeAsync(char.Torso.Position, workspace.testwAYPOINT.Position)
	
	for index, waypoint in pairs(path:GetWaypoints()) do
		local visual = Instance.new('Part', workspace)
		visual.Size = Vector3.new(4, 4, 4)
		visual.Material = 'Neon'
		visual.Shape = 'Ball'
	end
	
	for index, waypoint in pairs(path:GetWaypoints()) do
		print("Moving To:", waypoint.Position)
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end
end

Error:

AI:54: attempt to index nil with 'GetWaypoints'

ComputeAsync returns nil. It just modifies the path instance instead of returning a valid path.

1 Like

so, how would i fix this? i’ve took some code from roblox’s own documentation, so i don’t know what’s wrong.

you need to do :CreatePath()

local path = pathfindingService:CreatePath(pathParams)

i think i did that…

oh i’m blind ash :skull:

i think a pcall should fix it?
if not, try getting rid of the pairs

local succ, err, = pcall(function()
   path:ComputeAsync(params)
end

local waypoints = path:GetWaypoints()

if path.Status == Enum.PathStatus.Success and #waypoints > 0 then
		return waypoints 
end

EDIT:

try doing a for loop like this for movement, i think that should also do it:

function MoveTo(waypoints, humanoid: Humanoid)
	for i = 1, #waypoints do
		local waypoint: PathWaypoint = waypoints[i]

		if waypoint.Action == Enum.PathWaypointAction.Jump then
			humanoid.Jump = true
		end

		VisualizePath(waypoint)

		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end
end

Yep, pcall and the new loop fixed it. Thanks!

1 Like

Remove the path = path:ComputeAsync call

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.