In my tower defence game, my normal npc’s are moving from check point to checkpoint just fine but the boss I added just decides to skip everything… what’s going on?
Script
local dummy = script.Parent
local waypoints = workspace.AlphaMap.waypoint
for waypoint=1, #waypoints:GetChildren() do
dummy.Humanoid:MoveTo(waypoints[waypoint].Position)
dummy.Humanoid.MoveToFinished:Wait()
end
MoveTo times out after a couple of seconds(I think it is ten seconds). your faster smaller npcs can reach the checkpoint in the allotted time. But the boss will time out since it takes too long to finish the move.
so the fix is simply to check if the humanoid has reached its target in adittion to the MoveToFinished.
Like this:
–asA
for waypoint=1, #waypoints:GetChildren() do
repeat
dummy.Humanoid:MoveTo(waypoints[waypoint].Position)
until dummy.Humanoid.MoveToFinished:Wait()
end
The waypoint variable is a number so you’re trying to get an instance by its name with a number but names are strings. You need to convert the waypoint variable into a string.
local dummy = script.Parent
local waypoints = workspace.AlphaMap.waypoint
for waypoint = 1 , #waypoints:GetChildren() do
dummy.Humanoid:MoveTo(waypoints[tostring(waypoint)].Position)
dummy.Humanoid.MoveToFinished:Wait()
end
It’s fixed now (sorry for the late reply). I moved it to a module script with all my functions instead of having an individual script for each mob and that somehow seemed to fix it.