You’ll want to start at the lower left front corner and use 3 nested for loops to loop over each position in the volume.
You can get the corner like this:
local left_lower_front_corner = volume.CFrame:PointToWorldSpace( -volume.Size/2 )
local first_block_pos = left_lower_front_corner + Vector3.new(block_size/2, block_size/2, block_size/2)
You can set up the loops like so:
local block_size = 4
local block_prefab = Instance.new("Part")
block_prefab.Anchored = true
block_prefab.Size = Vector3.new(block_size, block_size, block_size)
local volume = script.Parent
local left_lower_front_corner = -volume.Size/2
local first_block_pos = left_lower_front_corner + Vector3.new(block_size/2, block_size/2, block_size/2)
for x = 0, volume.Size.X - block_size, block_size do
for y = 0, volume.Size.Y - block_size, block_size do
for z = 0, volume.Size.Z - block_size, block_size do
end
end
end
And create the blocks like this:
local block_offset_objectspace = Vector3.new(x, y, z)
local block_cframe = volume.CFrame * CFrame.new(first_block_pos + block_offset_objectspace)
local block = block_prefab:Clone()
block.Color = Color3.fromHSV(math.random(), 1, 1)
block.CFrame = block_cframe
block.Parent = game.Workspace
Here’s a working example that you can download and drag-n-drop into an open Studio window:
VolumeFiller.rbxm (3.0 KB)