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

Trying to generate a cube out of smaller cubes?

I would like to generate a large mass of blocks out of smaller blocks, for a building game to allow players to quickly add masses of parts (Why I want to make them out of smaller parts has to do with the way combat works) and the math on how to do this is lost on me.

I have been thinking of take the X Y and Z of a CFrame or V3 that the player enters and generating it like that in rows, but I do not even know how to spawn a part right beside another (almost like using a dragger tool to place the part at the exact position.)

Besides just compromising and making a different way of dealing damage so that the number of parts doesnt matter, how could I go about doing this?

(My math is atrocious due to a bunch of home life factors, so if you could explain the logic in laymans terms it would be very appreciated)

1 answer

Here's a small script that does what you want. There is a problem at Part.CanCollide = false. If you set it to true, the Parts don't line up as they should, but other than that, I think you're in the right direction with this script. Maybe someone else knows a way to bypass this.

local start = Vector3.new()
local blockSize = 2
local rowCount = 5

local posX = start.X
local posY = start.Y
local posZ = start.Z

local Model = Instance.new("Model", Workspace)
Model.Name = "Block"

for x = 1, rowCount do
	for y = 1, rowCount do
		for z = 1, rowCount do
			local Part = Instance.new("Part", Model)
			Part.CanCollide = false
			Part.Anchored = true
			Part.Position = Vector3.new(posX, posY, posZ)
			Part.Size = Vector3.new(blockSize, blockSize, blockSize)
			posZ = posZ + blockSize
		end
		posZ = start.Z
		posY = posY + blockSize
	end
	posY = start.Y
	posX = posX + blockSize
end

3 comments

0

I think I can get around that by just using CFrames and welding it together, considering I want people to be able to CFrame parts together anyway. I think I can easily make this form rectangles and other shapes as well. Thank you for the help, I am terrible at math as stated in the OP!

0

The problem is CFrame, setting position messes stuff up if the parts can collide.

0

In the future, please explain you code thoroughly instead of just posting it and saying "This works, try it" or something like it.

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