Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

A way of duplicating part x amount of times?

So, if i have this part, how can i duplicate it a random amount of times? I was thinking of something like this: (using in pairs loop)

local randomnumber = math.random(1,9) -- number between 1 and 9

for i,v in pairs
       --duplicate item (randomnumber) amount of times
       --im writing on mobile
end

4 comments

0

hello world!

0

for i = 1,randomnumber do (--insert code here--) end

0

Thx!

0

for loops

1 answer

✓ Accepted answer

Here is the code, I will explain after:

local item = your item
local randomnumber = math.random(1, 9)

for i = 1, randomnumber do
	item:Clone()
end

What this does, is it creates a random number and then does a loop that number of times. Every time it goes through the for loop, it adds 1 to i. The loop will break, or stop when i reaches randomnumber. You can additionally set the position, or whatever of each part like this:

local item = your item
local randomnumber = math.random(1, 9)

for i = 1, randomnumber do
	local new = item:Clone()
	new.Position = Vector3.new(0, i, 0) -- this will create a sort of tower, with each part on top of each other
end

Hope I helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.