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

Part Generation

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.

3 answers

✓ Accepted answer
local CurrentPos = Vector3.new(0, 0, 0)

for i = 1, 100 do 
	wait(0.1)
	local Part = Instance.new("Part", Workspace)
	Part.Anchored = true
	Part.Size = Vector3.new(2, 2, 2)
	CurrentPos = CurrentPos + Vector3.new(2, 0, 0)
	Part.Position = CurrentPos 
	if i % 10 == 0 then
		CurrentPos = Vector3.new(0, 0, CurrentPos.Z+2)
	end
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.

2 comments

0

But you aren't using the modulus operator at all?

0

As Waffle pointed out in his reply, it's apparently eaten if there are no spaces. I've edited what I posted.

for x=0,9 do
	for y=0,9 do
		local e=Instance.new("Part")
		e.FormFactor="Symmetric"
		e.Size=Vector3.new(2,2,2)
		e.Position=Vector3.new(x,0,y)*2
		e.Parent=workspace
	end
end

or if you only want one for loop:

for i=0,99 do
	local e=Instance.new("Part")
	e.FormFactor="Symmetric"
	e.Size=Vector3.new(2,2,2)
	e.Position=Vector3.new(i % 10,0,math.floor(i/10))*2
end

1 comment

0

apparently you have to add spaces to use the modulus operator on this website or it eats it.

Are you trying to copy me?!

1 comment

0

Copy? Was this question asked before? If it has, apologies, I didn't know.

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