Waypoints In Pathfinding Not Working

Im confused, if it’s always going to be true how come in the output it didn’t give any error?

Have you checked if it even reaches that part of the script?

1 Like

I see in your code you said “humanoid:MoveToFinishedWait(2)” when it should be 'humanoid.MoveToFinished:Wait(2)"

Here is a fixed version


local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local person = npc:WaitForChild("HumanoidRootPart")
local numWaypoints = 1
local goal = workspace.goal.Position


local pathService = game:GetService("PathfindingService")


function walkForward()
	local path = pathService:CreatePath({AgentRadius = 4,
		AgentHeight = 6, WaypointSpacing = 1, AgentCanJump = true, AgentCanClimb = true
	})
	
	path:computeAsync(person.Position, goal)


	local waypoints = path:GetWaypoints()

	if pathService:FindPathAsync(person.Position,goal) == Enum.PathStatus.NoPath then
		error("no path")
	end

	if waypoints == 0 or nil then
		error("waypoints is either nil or 0")
	end

	for i, waypoint in pairs(waypoints) do

		print("for loop running")
		print(waypoint.Position)
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait(2)
	end




	--local function blockedPath(blockedWaypointIdx) not sure if i really need this
	--	local path = pathService:CreatePath()

	--	if blockedWaypointIdx > numWaypoints then
	--		path:computeAsync(person.Position, goal)

	--		if path.Status == Enum.PathStatus.Success then
	--			walkForward()

	--			else

	--			error("path not found")
	--		end
	--	end
	--end

	--path.Blocked:Connect(blockedPath)
	humanoid:MoveTo(goal)
end

while true do
	walkForward()

	task.wait(1)
end
1 Like

Nope, after checking it seems like it should though. Which makes me even more confused.

Thanks, I have a question. Randomly I keep getting this error “PathfindingService: Path request failed due to a navmesh update error”. Is this my fault?

I don’t think they’ve solved this yet, but from the sound of it, if you have any meshes, it could be the problem.

PathfindingService Error: “Path request failed due to a navmesh update error” - Bug Reports / Engine Bugs - Developer Forum | Roblox

1 Like

Make some tests using the print function.

1 Like

Well I have 7.2k mesh parts so um maybe that’s the problem. :skull:

1 Like
local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local person = npc:WaitForChild("HumanoidRootPart")
local numWaypoints = 1
local goal = workspace.goal.Position


local pathService = game:GetService("PathfindingService")


function walkForward()
	print("1")
	local path = pathService:CreatePath({AgentRadius = 4,
		AgentHeight = 6, WaypointSpacing = 1, AgentCanJump = true, AgentCanClimb = true
	})
	print("2")
	path:computeAsync(person.Position, goal)
	print("3")
	print("4")
	local waypoints = path:GetWaypoints()
	print("5")
	if pathService:FindPathAsync(person.Position,goal) == Enum.PathStatus.NoPath then
		error("no path")
	end
	print("6")
	if waypoints == 0 or nil then
		error("waypoints is either nil or 0")
	end
	print("7")
	for i, waypoint in pairs(waypoints) do

		print("for loop running")
		print(waypoint.Position)
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait(2)
	end
	print("8")



	--local function blockedPath(blockedWaypointIdx) not sure if i really need this
	--	local path = pathService:CreatePath()

	--	if blockedWaypointIdx > numWaypoints then
	--		path:computeAsync(person.Position, goal)

	--		if path.Status == Enum.PathStatus.Success then
	--			walkForward()

	--			else

	--			error("path not found")
	--		end
	--	end
	--end

	--path.Blocked:Connect(blockedPath)
	humanoid:MoveTo(goal)
end

while true do
	walkForward()

	task.wait(1)
end

Im not sure if this is what you wanted me to do but all of the numbers were printed so I think it would have to go through the if statement.

That does not make sense, as if waypoints == 0 or nil then always returns true and should output the error, can you try putting a print inside that if statement?

1 Like

I think I am doing something wrong because it returns nil…

print(waypoints == 0 or nil)

This also returned false.

print(waypoints == 0 or waypoints == nil)

Try running this:

local npc = script.Parent
local humanoid = npc:WaitForChild("Humanoid")
local person = npc:WaitForChild("HumanoidRootPart")
local goal = workspace.goal.Position

local pathService = game:GetService("PathfindingService")

function walkForward()
    print("1")
    local path = pathService:CreatePath({
        AgentRadius = 4,
        AgentHeight = 6,
        WaypointSpacing = 1,
        AgentCanJump = true,
        AgentCanClimb = true
    })
    print("2")
    path:ComputeAsync(person.Position, goal)
    print("3")
    
    local pathStatus = path.Status
    if pathStatus == Enum.PathStatus.NoPath then
        error("no pathing found")
    elseif pathStatus == Enum.PathStatus.Complete then
        local waypoints = path:GetWaypoints()
        for i, waypoint in pairs(waypoints) do
            print("flag lr")
            print(waypoint.Position)
            humanoid:MoveTo(waypoint.Position)
            humanoid.MoveToFinished:Wait()
        end
    else
        error("path status: " .. tostring(pathStatus))
    end

    print("8")
    humanoid:MoveTo(goal)
end

while true do
    walkForward()
    task.wait(1)
end
1 Like

Yea it gives an error now


if pathStatus == Enum.PathStatus.NoPath then
		error("no pathing found")

Have you turned on any of the visuals like “show navigation mesh” to see what it’s seeing?

1 Like

I turned on both settings. I don’t see anything different, am I doing something wrong?

Sorry I don’t have an answer for you, but that is the problem. I am away right now and will try to help more if needed when I get home.

1 Like

Alright thanks for the help! :happy1:

It turns out I can see the visualizations on my friends game but not on my game… I think it’s because it cant make a path.

Does it show on the land below the parts in your game?

1 Like