Having lag issues with npc army

  1. I’m trying to make it so that the player controls their army by clicking the mouse where the want the army to go, the army moves in formation.

  2. The issue is that I keep getting a lag sometimes when the army is moving. The “lag” , Basically sometimes all of the npcs move, sometimes only some moves at different times than others.

  3. I’ve tried using minimal parts on the npc Like shown here , This happenes . I’ve checked on scripting helpers, google and I’ve searched around the forum and still can’t find anything to help.

This is what I am trying to accomplish all the time, with 100+ troops if possible https://gyazo.com/f2f643a2e63c70674766024c0b9e8bfb

This is how I move to troops.

local player = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()

local activeArmy = workspace.Troops:GetChildren()

local function MoveTo(pos)
	activeArmy = workspace.Troops:GetChildren()
	if #activeArmy < 1 then
	local xinc = 0
	local yinc = 0
	local inc = 2
	local perRow = math.floor(math.sqrt(#activeArmy))
	for i, v in pairs (activeArmy) do
		local position = pos + Vector3.new(xinc, 0, yinc)
		xinc += inc
		if xinc > (perRow * inc) then
			xinc = 0
			yinc += inc

	local target = Mouse.Target
	if target and target.Parent then
		if target == workspace.SpawnLocation then
		local moveToCFrame = Mouse.Hit.Position

I tried to make this as bare minimal as possible to see if I can figure out this issue, but I just can’t seem to find the solution. Am I just trying to do too much at once? I don’t know.

I don’t know if I’m just moving them ineffectively, or something else.
I’m not sure what else to try here. Any help is appreciated. If I have missed anything or didn’t explain something well enough, please feel free to ask and I’ll do my best to answer! Thank you!

My only thoughts are that you are running this on a LocalScript, and not all soldiers are loaded locally? There seems to be a distance which is not loading. Can you send the move position to a Script and try again? Logic looks sound.

Maybe add a print(#activeArmy) in there so you can see what is happening locally

I’m not exactly sure why, but it works now that I’m moving them on the server. I added a print(#activeArmy) in the local script and it was printing the same amount as on the server, So there I don’t know lol. But now my little troops are all moving how they should. Thank you very much!

1 Like

In order to preserve client resources, they restrict the number of models that are replicated on the client, with the rest handled through streaming. That’s a large army! Glad it works!

1 Like