What do you want to achieve? Keep it simple and clear!
Im trying to getting all the enemy npc’s to get to their current waypoint before moving to the next waypoint
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking this up but it seems to specific for me to find anything on it.
This is the code i use to move the npcs
function mob.Move(mob, map)
local hum = mob:WaitForChild("Humanoid")
local waypoints = map.Waypoints
for waypoint=1, #waypoints:GetChildren() do
hum:MoveTo(waypoints[waypoint].Position)
hum.MoveToFinished:Wait()
end
mob:Destroy()
end
return mob
This started happening after i changed the walkspeed of the enemies but i dont think that would affect anything
MoveToFinished has an 8 second timeout… so if it will take longer than that than call another MoveTo before the MoveToFinished so that it refreshes the function.
Because of the timeout with Humanoid:MoveTo(), it would be more effective to check distance from the waypoint rather than wait for MoveToFinished.
for waypoint=1, #waypoints:GetChildren() do
repeat
hum:MoveTo(waypoints[waypoint].Position)
wait()
--adjust the 0.2 to increase/decrease the threshold to move to next waypoint
until ((mob.RootPart.Position - waypoints[waypoint].Position) * Vector3.new(1,0,1)).Magnitude <= 0.2
end
Multiplying the Vector3 by (1,0,1) means that it’s only going to get the Distance between them horizontally, not vertically. It effectively takes the Y component out of the Distance calculation, so the Height of your NPCs won’t make a difference.
You should check if the function gets fired more than once in the same second with a print. It’s probably not the case but I did have this issue before.