NPC not going to waypoint

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
3 Likes

Did you mean to get a list of all waypoints instead of just one when you wrote

local waypoints = workspace.AlphaMap.waypoint

?

It looks like you aren’t referencing a table.

for waypoint, number in pairs(waypoints:GetChildren()) do
      dummy.Humanoid:MoveTo(waypoint.Position)
      dummy.Humanoid.MoveToFinished:Wait()
end

Can you show us the waypoints in the explorer? It could be looping through the waypoints in a random order.

They are all numbered and it’s literally the same script I used for my default mobs and those work fine

local waypoints = workspace.AlphaMap.waypoint

This was the folder holding all the waypoints

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

Voilas!

3 Likes

It’s still broken for some reason… I tried your way and the boss just started turning backwards and stuff

If all the variables are still the same, and the waypoints are in the folder, this should work.

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

Could you show me a video of the Boss turning backwards and your code?

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.

1 Like