Pathfinding kind of wonky?

So basically I want to make a pathfinding script, however, the pathfinding code says the status is “NoPath”, but it still returns valid waypoints, but sometimes it just returns nil. No errors. Does anyone know a fix (see snippet below)?

function pathfind(dummy, goal)
	for _, item in pairs(goal.Parent:GetChildren()) do
		if item:IsA("BasePart") then
			item.CanCollide = false
		end
	end
	local humanoid = dummy:WaitForChild("Humanoid")
	local root = dummy.PrimaryPart
	
	local path = ps:CreatePath({AgentCanJump = false})
	
	local goalpos = goal.Position
	if string.find(goal.Name, "Entrance") then
		goalpos = Vector3.new(goalpos.X, 3, goalpos.Z)
	end
	path:ComputeAsync(root.Position, goalpos)
	for _, item in pairs(goal.Parent:GetChildren()) do
		if item:IsA("BasePart") then
			item.CanCollide = true
		end
	end
	local waypoints = path:GetWaypoints()
	print(waypoints)
	for i, waypoint in ipairs(waypoints) do
		humanoid:MoveTo(waypoint.Position)
		humanoid.MoveToFinished:Wait()
	end
	if goal.Name == "Seat" then
		goal.Disabled = false
		goal:Sit(humanoid)
	end
end

Nevermind, I just realized that they were stuck in the chair, so they couldn’t move. I’m still not sure why the path.Status is printing NoPath though…

1 Like

I think you just saved me from a painful, spiral into madness of figuring out pathfinding. I know this isn’t helpful, but i think you might’ve saved me.

Hey! I am pretty sure it says no path if something is blocking the path, as currently, you don’t have it re-compute if or when there is something blocking the path.

The problem is it returns valid waypoints even when the path is blocked for some reason. Another weird problem is that the npcs are lagging? I set the networkowner to nil, and according to google it should fix it, but it doesn’t…

Interesting. I used this code on my pathfinding code and it instantly made the lagging stop. I’m not quite sure why that didn’t work for you.

Character. PrimaryPart:SetNetworkOwner(nil)

Wrap the compute in a pcall that way it would actually tell you if the path wasn’t possible. I think the no-path is the code saying the path computed was not possible.

kk. I realized i had done everything but the primary part lol

Oh. Does that now work? And for the “No Path”, wrap it up in a call that way it can tell you if the path was blocked.

Also, just out of curiosity how did you get the programmer tag?

Oof- It still doesn’t work. As for the “No Path” I think its just a studio bug.

Go to your summary->preferences->it should be like flair and title I think

This is kind of off topic, but it seems like the npc’s collision groups also don’t work.
Edit: It actually might be the fact that they are colliding that is making the npcs lagging, but im not sure.

I don’t believe it’s a bug, did you wrap the compute in a pcall?

I’ll try but it probably wont do anything because nothing is erroring.

Have you tried using :SetNetworkOwner() and not :SetNetworkOwner(nil)

You need to use nil to set it to the server.

nil is not required, my script uses it without nil.

local pathparams = {
[“WaypointSpacing”] = math.huge}
There are a lot more pathparams you can use. Also in the :Create when you’re creating the path, put pathparams in the parentheses.

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