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)
1 | local randomnumber = math.random( 1 , 9 ) -- number between 1 and 9 |
2 |
3 | for i,v in pairs |
4 | --duplicate item (randomnumber) amount of times |
5 | --im writing on mobile |
6 | end |
Here is the code, I will explain after:
1 | local item = your item |
2 | local randomnumber = math.random( 1 , 9 ) |
3 |
4 | for i = 1 , randomnumber do |
5 | item:Clone() |
6 | 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:
1 | local item = your item |
2 | local randomnumber = math.random( 1 , 9 ) |
3 |
4 | for i = 1 , randomnumber do |
5 | local new = item:Clone() |
6 | new.Position = Vector 3. new( 0 , i, 0 ) -- this will create a sort of tower, with each part on top of each other |
7 | end |
Hope I helped!