Hey fellow developers. So my pathfinding script for a NPC worked perfectly a few months ago and now when I came back to it, it fails to work in my game. Also, if I put the NPC in an empty baseplate server it works perfectly like normal. Is there an explanation for this? I am totally confused. I am assuming that path:GetWaypoints() is broken or something.
Revised Post: So the problem apparently is that pathfindingservice is not generating a path in my game, but it works fine in a normal baseplate after hours of testing. Anyone know why this is the case?
Edit 2: I tried tampering with the collision editors, but to no avail.
if position.Value == “Hiker” then
local idleanim = script.Parent.Animation1
local runanim = script.Parent.RunAnim
local idleanimtrack = hum:LoadAnimation(idleanim)
local runanimtrack = hum:LoadAnimation(runanim)
idleanimtrack:Play()
idleanimtrack:Stop()
print("ok")
if ladder ~= true then
runanimtrack:Play()
local pathfindingservice = game:GetService("PathfindingService")
local path = pathfindingservice:CreatePath()--creates a path object
path:ComputeAsync(torso.Position,vector3.Value)--computes a path
local waypoints = path:GetWaypoints()
local distance
print("ok2")
for i,waypoint in pairs(waypoints) do
local waypointPosition = waypoint.Position
print("looping!")
if waypoint.Action == Enum.PathWaypointAction.Jump then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
hum.Seated:Connect(function(seated)
if seated == true then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end)
path.Blocked:Connect(function()
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end)
hum:MoveTo(waypoint.Position)
repeat
distance = (waypointPosition - hum.Parent.PrimaryPart.Position).magnitude
wait()
print(distance)
print("waiting")
until
distance <= 6.05
print("here")
end
print("dumbo")
runanimtrack:Stop()
idleanimtrack:Play()
end
It’s a Vector3.new() value I just named it vector3 that isn’t the issue lol. The issue is that the paths aren’t generating in my game for some reason. The path creations fails every time in my game for some reason. If I do print(tostring(path.Status)) the result is NoPath.
Hmm, that’s weird. I’m sorry I’m not good enough with pathfinding to help you. Good luck solving it though, I’m sorry I couldn’t be of more help.
I managed to solve it myself. The issue was apparently some lingering terrain that was outside my map. I managed to figure this out after a bunch of testing. It was a real pain to find the misplaced terrain, but deleting the terrain fixed my pathfinding. Hope this helps!