How do I make A marching NPC army?

So I am trying to make at least 40 npcs march around the map but the script I use works but it makes the npc stutter and messes up the line. After the final waypoint the script decides not to work and gives out an error saying waypoint doesn’t exist. Is there an efficient way to make this?

3 Likes

Mind sending the script you are using?

3 Likes

Can you send it as message, cause its pretty hard to read it.
Just copy it and paste it with ``` infront of it and at the end

1 Like

do you mind giving out a rbxl. file so we can look more into it?

1 Like

Try getting rid of the while loop and remove this line of code:

humanoid.MoveToFinished:Wait()
1 Like

"local waypoints = game.Workspace.Waypoints
local humanoid = script.Parent:WaitForChild(“Humanoid”)

while true do
for waypoint = 1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
end
end"

Recruit Soldier.rbxm (16.7 KB)

That just breaks the script and also I am looping it the march so it’s constant

The reason your soldiers are messing up the line is because of this piece of code :point_down::point_down::point_down:

humanoid.MoveToFinished:Wait()

Every time a Humanoid starts moving it waits and then another Humanoid moves. This means the soldiers don’t start walking at the same time. Since a while loop needs to wait or else your game will freeze, then I suggest replacing your while loop with a for loop and getting rid of :point_down:

humanoid.MoveToFinished:Wait()

Example:

local waypoints = game.Workspace.Waypoints
local humanoid = script.Parent:WaitForChild(“Humanoid”)
local repeatCount = 10 -- change this to the number of times the for loop will loop through the code

for i = 1, repeatCount, 1 do
for waypoint = 1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
end
end

You can use this and change the repeatCount variable to the number of times you want to loop your code. Another solution would be to remove this line of code :point_down:

humanoid.MoveToFinished:Wait()

And add task.wait() outside of the for loop, but still inside of the while loop. Like this :point_down:

local waypoints = game.Workspace.Waypoints
local humanoid = script.Parent:WaitForChild(“Humanoid”)

while true do
for waypoint = 1, #waypoints:GetChildren() do
humanoid:MoveTo(waypoints[waypoint].Position)
end
task.wait() -- inside of the brackets you can also add a number if you want to wait a specific amount of time
end

Okay dude your script doesn’t work. The npc does not move through the way points and once I run it the npc either stops walking after the 2nd way point or on the last script the npc just walks in place.

Please ensure your testing the script in studio first before making a suggestion. I need solutions not theories!