Issues with pathfinding - waypoints are not set

Hello everyone. I am facing problems with pathfinding for some time now. After a few days of unsuccessful research, I decided to come for help here.

When computing path, that is where the problem happens.


It does not show any error, when printing ‘s’, it prints ‘true’.
However, when I did some debugging, I noticed that it does not return any waypoints.
image
image

Path creation is outside of the NPC move function:
image

If you need more details, let me know. Thank you in advance for any help.

Help is still needed and will be greatly appreciated.

Could you send the entire script so I can have a better idea of what the issue could be?
And if possible, tell me if it is a LocalScript or a ServerScript.

1 Like

Server script, entire code:
I hope it is not confusing!!

function MoveNpc(npc,destination,canSit,errored)
	
	print("triggered")
--	if DangerZone then
--		path.Costs = {DangerZone}
--	end
	--DangerZone = nil
	local anchoreo = npc.HumanoidRootPart.Anchored
	npc.HumanoidRootPart.Anchored = false
	
	local time = tick()
	if errored == true then
		print("second program activated.")
		return;
	end
	if canSit == true then
		CanSitAmelieCafe.Value = true
	else
		CanSitAmelieCafe.Value = false
	end
	local human = npc.Humanoid
	
	local s,e = pcall(function()
		path:ComputeAsync(npc.HumanoidRootPart.Position,destination.Position)
	end)
	
	if not s then
		print("ERROR WITHIN COMPUTING:",e)
		return
	else
		print(s)
	end
	
	if npc:FindFirstChildWhichIsA("WeldConstraint") then
		npc.WeldConstraint.Enabled = false
		print("disabled")
	end
	
	local Waypoints = path:GetWaypoints()
	
	warn("AHAAAAAAAAAAAAAA",#Waypoints)

	local distance
	curnp = npc
	cursi = canSit
	curer = errored
	for _,point in pairs(Waypoints) do
		print("pong")
		curdes = destination
		curwp += 1
		if point.Action == Enum.PathWaypointAction.Jump then
			human:ChangeState(Enum.HumanoidStateType.Jumping)
		end
		
		print("is the dam npc even moving and not tping right away???")
		
		human:MoveTo(point.Position)
		local finish = false
		
		local connection
		
		connection = human.MoveToFinished:Connect(function(reached)
			--print("finished.",reached)
			finish = true
			connection:Disconnect()
			
		end)
		
		repeat 
			distance = (point.Position - npc.PrimaryPart.Position).Magnitude
			if finish then break end
			task.wait()
		until distance <= 5 or finish == true
		connection:Disconnect()
	end
	task.wait()
	if canSit == true then
		pcall(function()
			workspace.Tables.AmelieTable.AmelieSeat.Seat:Sit(workspace.AmeliEcafe.Humanoid)
		end)
		--CheckIfSat(npc,destination)
	end
	npc.HumanoidRootPart.Anchored = anchoreo
end

Just to know, is the “destination” an Instance or a Vector3?
I’m assuming it is an Instance judging by the code.
Also, can I assume you just did not include a path instance in the script you sent here? 'Cause I couldn’t find any variable in the code that directly referenced a path.

1 Like

The path is outside of the script, because I have for example a blocked function attached to path.

destination is an Instance.

May you please @tusart in the next post, I don’t get notified and I want to answer you faster than I am currently. @Zoiudolo

@tusart I focused on this section of your code, and I kid you not I got it working first try which is quite confusing… (And I didn’t even edit it at all…)
Max I did was creating a path so I could have a reference instance and setting up an NPC + destination.

local path=game:GetService("PathfindingService"):CreatePath()
local npc=workspace.Dummy
local destination=workspace.Part
local s,e = pcall(function()
	path:ComputeAsync(npc.HumanoidRootPart.Position,destination.Position)
end)

if not s then
	print("ERROR WITHIN COMPUTING:",e)
	return
else
	print(s)
end

if npc:FindFirstChildWhichIsA("WeldConstraint") then
	npc.WeldConstraint.Enabled = false
	print("disabled")
end

local Waypoints = path:GetWaypoints()
warn(#Waypoints)

No clue what happened on your end, but clearly this section is not faulty.

1 Like

Do you think the problem can be when I have the path attached to a blockedPath function? I will try to experiment more and do further research, then let you know. In case you get any more info, I am here anytime.

Forgot to let you know that my game has a lot of parts making it very laggy, I had to set streaming enabled on to a radius of 100 to get better performance, BUT the NPC won’t walk even if streaming enabled is off.

Well, I will test that out right now, I will let you know if I run into any issues or not.


@tusart bruh this code is a whole nother level that i even gave up from acting formally :skull:
(also i dont mean this in a mean way, the code itself is fine, its just that i was surprised to see there was actually no issues going on)

local path=game:GetService("PathfindingService"):CreatePath()
local npc=workspace.Dummy
local destination=workspace.Part
local errored=false
local canSit=false
local anchoreo = npc.HumanoidRootPart.Anchored
npc.HumanoidRootPart.Anchored = false

local time = tick()
if errored == true then
	print("second program activated.")
	return;
end
local human = npc.Humanoid

local s,e = pcall(function()
	path:ComputeAsync(npc.HumanoidRootPart.Position,destination.Position)
end)

if not s then
	print("ERROR WITHIN COMPUTING:",e)
	return
else
	print(s)
end

if npc:FindFirstChildWhichIsA("WeldConstraint") then
	npc.WeldConstraint.Enabled = false
	print("disabled")
end

local Waypoints = path:GetWaypoints()

warn("AHAAAAAAAAAAAAAA",#Waypoints)

local distance
curnp = npc
cursi = canSit
curer = errored
curwp = 0
for _,point in pairs(Waypoints) do
	print("pong")
	curdes = destination
	curwp += 1
	if point.Action == Enum.PathWaypointAction.Jump then
		human:ChangeState(Enum.HumanoidStateType.Jumping)
	end

	print("is the dam npc even moving and not tping right away???")

	human:MoveTo(point.Position)
	local finish = false

	local connection

	connection = human.MoveToFinished:Connect(function(reached)
		--print("finished.",reached)
		finish = true
		connection:Disconnect()

	end)

	repeat 
		distance = (point.Position - npc.PrimaryPart.Position).Magnitude
		if finish then break end
		task.wait()
	until distance <= 5 or finish == true
	connection:Disconnect()
end
task.wait()
npc.HumanoidRootPart.Anchored = anchoreo

WELL, safe to assume it is indeed the blockedPath function since all I did to test the code out this time was just removing the seating stuff. :’)

Alright, thank you. I will try the code without the blockedpath function, then let you know if it worked or not.

@Zoiudolo Good news. The problem was finally fixed after even further research ( I am confusingly satisfied by how I found the post when I could find it before).

The problem was that in the workspace, there was Humanoid. Just that managed to break the whole pathfinding system, but now it is working well! I want to thank you for your time spent helping me as it definitely helped me move further.

Have a great day and stay safe! :slight_smile:

1 Like

Hey there, great to see you managed to find the issue, and no problem, time is something I have a lot to spare!

1 Like