Cloning multiple parts at the same time

How would I clone all parts in a folder at the same time?

Instead of just this way -

local Ball1 = game.replicatedstorage.Balls.Ball1
local Ball2 = game.replicatedstorage.Balls.Ball2
local Ball3 = game.replicatedstorage.Balls.Bal3

while true do
Ball1:Clone
Ball2:Clone
Ball3:Clone
wait(1)
end

Thanks

1 Like

simply use a pairs loop:

--i - index. v - value, the ball instance.
for i, v in pairs(game:GetServer('ReplicatedStorage').Balls:GetChildren()) do 
     v:Clone().Parent = workspace
end

Its giving me an error -

"GetServer is not a valid member of DataModel “Game”

They meant to use GetService instead.

game.replicatedstorage.Balls.Bal3

You’ve spelled ‘Ball3’ here incorrectly by the way.

replicatedstorage

and service names should use pascal case, i.e; ‘ReplicatedStorage’.

Thanks! And what I wrote as an example was just quick and messy as I made something up on the spot.

One more thing I forgot to include. Is there any way to delete everything that was just cloned a few seconds after. So for example, parts get cloned and after 10 seconds those cloned parts get deleted. Thanks.

for i, v in pairs(game:GetService('ReplicatedStorage').Balls:GetChildren()) do
	local c = v:Clone()
	game.Debris:AddItem(c, 10) --'10' is current lifespan
	c.Parent = workspace
end
2 Likes

One last thing I’m sorry. I tried adding while true do on top of this, but it gives me the error of timing out.

while true do
for i, v in pairs(game:GetService('ReplicatedStorage').Balls:GetChildren()) do
	local c = v:Clone()
	game.Debris:AddItem(c, 10) --'10' is current lifespan
	c.Parent = workspace
end
end

Thanks again.

Change it to:

while wait(1) do
for i, v in pairs(game:GetService('ReplicatedStorage').Balls:GetChildren()) do
	local c = v:Clone()
	game.Debris:AddItem(c, 10) --'10' is current lifespan
	c.Parent = workspace
end
end

Right now your code is executing constantly without waiting which leads to it timing out.

1 Like

It works but it spawns a whole bunch of them.

I just want too spawn 5 snowballs and then wait 10 seconds and delete those 5 snowballs. And I want this process to repeat over and over again.

while wait(10) do
	for i, v in pairs(game:GetService('ReplicatedStorage').Balls:GetChildren()) do
		local c = v:Clone()
		game.Debris:AddItem(c, 10) --'10' is current lifespan
		c.Parent = workspace
	end
end

Simply change the wait to 10 seconds then.

1 Like