I’m making a game, and in the game there’s an npc who moves by 7 different positions in a order, for some reason, the :MoveToFinished() i added fires less than halfway through the way, my npc’s walkspeed is 2, when i set the enemy’s walkspeed to 16, it does it just fine, how can i fix this?
My script:
local zombie = script.Parent
for count = 1,#game.Workspace.WayPoints:GetChildren(),1 do
wait(0.1)
zombie.Humanoid:MoveTo(workspace.WayPoints:FindFirstChild(tostring(count)).Position)
zombie.Humanoid.MoveToFinished:Wait()
wait(0.05)
end
wait(0.6)
game.ReplicatedStorage.HP.Value = game.ReplicatedStorage.HP.Value - script.Parent.Humanoid.Health
zombie:Destroy()
EDIT: I just found out that it’s actually the :MoveTo() that for some reason ends early before reaching the wanted point.
EDIT 2: Setting WalkToPoint gives the same result, and setting WalkToPart does absolutely nothing.
I’m no expert but I think that’s a Roblox problem. But a solution might be to add a yield like you are doing but scale the yield according to the WalkSpeed.
So I tested your code and I think I know what’s happening. There is a “timeout” with the :MoveTo() function which is 8 seconds. If the npc cannot move to the position or part within 8 seconds it will give up.
But on Humanoid:MoveTo the code sample is really good and I would recommend using it to fix your problem.