Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I stop an NPC from following its pathfinding route?

Asked by 4 years ago
wait(3)
local torso = script.Parent.Torso.Position
local endpoint = game.Workspace.WalkPointPart.Position
local hum = script.Parent.Humanoid


local path = game:GetService("PathfindingService"):FindPathAsync(torso,endpoint)
local points = path:GetWaypoints()
if path.Status == Enum.PathStatus.Success then
    for i,v in pairs(points) do
        hum:MoveTo(v.Position)
        hum.MoveToFinished:wait()
        if v.Action == Enum.PathWaypointAction.Jump then
            hum.Jump = true
        end
    end
end
print("goal reached")

I ran into a problem when using pathfinding. when the character gets to the part it wants to get to, it keeps trying to walk to it unless it walks in the center of the part. it finishes its goal if I turn the part cancollide false but I dont want this behavior. is there something I can do to cancel the pathfinding while its running?

Answer this question