Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

A way of duplicating part x amount of times?

Asked by 5 years ago
Edited 5 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

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
0
hello world! Clasterboy 72 — 5y
0
for i = 1,randomnumber do (--insert code here--) end xEmmalyx 285 — 5y
0
Thx! Clasterboy 72 — 5y
0
for loops LoganboyInCO 150 — 5y

1 answer

Log in to vote
0
Answered by
U_srname 152
5 years ago

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!

Ad

Answer this question