So I have an NPC follow script, and I've had this issue for a while. When you kill the NPC, the follow script just stops working with no errors in the output.

function ready(tmp_plr)
game:GetService("RunService").Stepped:connect(function()
local yes, error = ypcall(function()
if (math.abs((tmp_plr.Character.Head.Position-script.Parent.Head.Position).magnitude)) < 90 then
script.Parent.Humanoid:MoveTo()(tmp_plr.Character.Head.Position)
else print("Humanoid not found")
end 
end) 
end)
end
game.Players.PlayerAdded:Connect(function(p)
ready(p)
end)

2 comments

0

My own thoughts are that maybe it's because you are only calling the function only once, whereas you might need to not loop it, but keep it in a steady cycle somehow like with coroutines or maybe you could put in an if statement that catches the possibility of a respawn. Also where is the script, if it's inside the npc then you'll probably need to move it externally because it will cease existing

0

even if I put it outside of the npc it stops working when it dies..