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

Generating parts within a set area?

I've been working for about an hour now and for the life of me I cant seem to figure out how to randomly generate parts within an area. I've made a part 100x2x100 and I've been trying to fit 10x10 parts inside of it that have random properties. The random properties I can do but I cant wrap my head around the math.

2 answers

✓ Accepted answer

Looks like you're trying to make a grid. The correct way to do this would be Numerical For Loops.

local int = 5

for x = -int, int - 1 do
	for z = -int, int - 1 do
		local part		= Instance.new("Part", workspace)
		part.Size		= Vector3.new(10, 2, 10)
		part.Position	= Vector3.new(x*10, 1, z*10)
	end
end

You simply take the outside most positions as parameters. So for your 100X2X100 part, if it is at position 0,0,0.

Take half of 100(50) so it it 50 in each direction.

while wait() do
local p = Instance.new("Part",game.Workspace)
p.Anchored = true
p.Size = Vector3.new(10,10,10)
p.CFrame = CFrame.new(math.random(-50,50),7,math.random(-50,50))
end

math.random gives you a random number inbetween your parameters.

Hope This Helps :)

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