Say I wanted to generate 100 2x2x2 parts in a square perfectly fitting together. I started with a for loop and generated 100 2x2x2 parts, but I'm not sure what to do from there.
01 | local CurrentPos = Vector 3. new( 0 , 0 , 0 ) |
02 |
03 | for i = 1 , 100 do |
04 | wait( 0.1 ) |
05 | local Part = Instance.new( "Part" , Workspace) |
06 | Part.Anchored = true |
07 | Part.Size = Vector 3. new( 2 , 2 , 2 ) |
08 | CurrentPos = CurrentPos + Vector 3. new( 2 , 0 , 0 ) |
09 | Part.Position = CurrentPos |
10 | if i % 10 = = 0 then |
11 | CurrentPos = Vector 3. new( 0 , 0 , CurrentPos.Z+ 2 ) |
12 | end |
13 | end |
The above would do as you require.
The modulus operator, %, is used to return the remainder of the division between two given numbers. In this case I'm using it in an if statement to check if something is a multiple of ten, when it is it starts a new line on the Z-axis (allowing for a 10x10 square).
The rest is pretty self explanatory.
1 | for x = 0 , 9 do |
2 | for y = 0 , 9 do |
3 | local e = Instance.new( "Part" ) |
4 | e.FormFactor = "Symmetric" |
5 | e.Size = Vector 3. new( 2 , 2 , 2 ) |
6 | e.Position = Vector 3. new(x, 0 ,y)* 2 |
7 | e.Parent = workspace |
8 | end |
9 | end |
or if you only want one for loop:
1 | for i = 0 , 99 do |
2 | local e = Instance.new( "Part" ) |
3 | e.FormFactor = "Symmetric" |
4 | e.Size = Vector 3. new( 2 , 2 , 2 ) |
5 | e.Position = Vector 3. new(i % 10 , 0 ,math.floor(i/ 10 ))* 2 |
6 | end |
Are you trying to copy me?!