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
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.
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.
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.