How do I a lot at once and in a certain place or formation

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to spawn like 20 all at once and not once 30 times. I also want them to not spawn at 1 place only and maybe spawn in a formation? or something like that?
  2. What is the issue? Include screenshots / videos if possible!
    I don’t know how to do this because I’m pretty know so I don’t know how to script.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried searching google and forums
local rp = game:GetService("ReplicatedStorage")
local remote = rp:WaitForChild("Teleport")
local player = game:GetService("Players")



print("test1")

remote.OnServerEvent:Connect(function(player)
	local character = player.Character.PrimaryPart
	
	local function spawnsoldier()
	
	local ssoldier = rp:WaitForChild("RomanSoldier")
	local Soldier = ssoldier:Clone()
	Soldier.Parent = game.Workspace
	wait(0.4)
	Soldier.HumanoidRootPart.CFrame = character.CFrame * CFrame.new(10,0,0)
	
end
	
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	spawnsoldier()
	
	print("test2")
end)

use a for loop

for i = 1,30 do
   spawnsoldier()
end
1 Like

you can use a for loop like @TenBlocke said. You can also make the soldiers root part position or CFrame random. Kinda like this

for count = 1, 30, 1 do
   spawnSoldier()
   if soldier.HumanoidRootPart THEN
     soldier.HumanoidRootPart.CFrame = char.CFrame * CFrame.New{math.random(-10,10), char.Position.Y,math.random(-10,10))
   end
end

this is pseudo code and probably wont work if you just copy and paste. I wrote it just to get you a general idea :slightly_smiling_face:

EDIT: If you want the soldiers to spawn in a formation id assume youd have to look up some cframe formula :sweat_smile:

2 Likes

Is there a way for it to be 30 at the same time instead of spawning 1 30 times?

Are you referring to the fact one spawns, it waits a bit, and then it spawns another? According to your function, you have wait(0.4). That line right there is going to wait 0.4 seconds before it spawns another one. Try removing that, not sure if I’m understanding you correctly here.

If i remove it it will spawn before I teleported. It looks something like this

Is there any fix for this?

30 things, one at a time, versus 30 things in ReplicatedStorage, reparented to workspace in one command?

You won’t see the difference. Roblox will take the 30 things and process them in some order anyway. 30 will be lightning fast, either way.

When you get to 10000 things, preloading provides the illusion of speed. Load them 1 at a time in a folder in Replicated, then move the folder.

I know I’m a bit late to this but can’t you just move the wait out of the function and to before the for loop? Moving it to before the for loop will make it have no delay and spawn after teleporting.

thanks, idk why i didn’t think of that im so dumb