Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] How do I stop a path? (Pathfinding Service)

I've attempted moving the humanoid (:MoveTo()) to the humanoidrootpart, anchoring the HRP (humanoidrootpart) for a split second, and killing the humanoid doesn't work.

In general im trying to make the npc stop when killed.

pathfinding script:

local ps = game:GetService("PathfindingService")
local hum = script.Parent.Humanoid
local hrp = script.Parent.HumanoidRootPart
local path = ps:CreatePath()
--//
path:ComputeAsync(hrp.Position, game.Workspace.endpart.Position)
for _,waypoint in pairs(path:GetWaypoints()) do
	if waypoint.Action == Enum.PathWaypointAction.Jump then
		hum:ChangeState(Enum.HumanoidStateType.Jumping)
	end
	if hum.Health > 0 then
		hum:MoveTo(waypoint.Position)
		hum.MoveToFinished:Wait(2)
	end	
end
--//
if hum.Health > 0 then
	hum:MoveTo(game.Workspace.endpart.Position)
end	

1 comment

0

can you provide more code

1 answer

✓ Accepted answer

Can you try this please?

local ps = game:GetService("PathfindingService")
local hum = script.Parent.Humanoid
local hrp = script.Parent.HumanoidRootPart
local path = ps:CreatePath()
--//
path:ComputeAsync(hrp.Position, game.Workspace.endpart.Position)
for _,waypoint in pairs(path:GetWaypoints()) do
    if waypoint.Action == Enum.PathWaypointAction.Jump then
        hum:ChangeState(Enum.HumanoidStateType.Jumping)
    end
    if hum.Health > 0 then
        hum:MoveTo(waypoint.Position)
        hum.MoveToFinished:Wait(2)
    end 
end
--//
if hum.Health > 0 then
    hum:MoveTo(game.Workspace.endpart.Position)
end 

hum.Died:Connect(function()
	hum:MoveTo(hrp.Position)
end)

1 comment

0

After a few weapon tests, I learned that it must have been the free model guns I was using for testing. I used the roblox linked sword and it worked, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.