I want to make a script that will take a 6x6 Block from lighting and then randomly place it inside of a Transparent 54x54 brick, but my question is how can i fill the brick? I am guessing i have to do something with math with a CFrame but i'm not sure where to go with it.
✓ ANSWER ACCEPTED
How can i fill a block with bricks?
1 answer
✓ Accepted answer
You should store objects in ServerStorage and not in Lighting.
If you want to place the part somewhere within the boundaries of the box, you can multiply the block's CFrame by some offset to translate it.
block.CFrame = box.CFrame * CFrame.new(Vector3.new(math.random()*2-1, math.random()*2-1, math.random()*2-1)*27)
If you only want it to be placed in 6x6x6 cells within the box:
block.CFrame = box.CFrame * CFrame.new(math.random(-4,4)*6, math.random(-4,4)*6, math.random(-4,4)*6)
In order to fill the whole box you can just loop on each axis
for x=-4,4 do
for y=-4,4 do
for z=-4,4 do
local new = block:Clone()
new.CFrame = box.CFrame * CFrame.new(x*6, y*6, z*6)
new.Parent = box.Parent
end
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
