what im trying to do is create a block system which has 4 parts in each block and im trying to make it so it looks like this: what i want but for some reason its looking like this instead: weird shape into some diagonal shape instead of a square but I cant seem to find any bugs that are causing it in my code

local z, x = 0, 0
local z2, x2 = 0, 0
local size = Vector3.new(10,20,10)
local gap = 2.5
local blockamount = 2
--size of a block from :GetExtentsSize() = 22.5, 20, 22.5

local function createblock()
	local model = Instance.new("Model")
	local part = Instance.new("Part")
	
	for blockcolumn = 1,blockamount do
		for blockrow = 1,blockamount do
			local part = Instance.new("Part")

			part.Anchored = true
			part.Size = size
			part.CFrame = part.CFrame + Vector3.new(z+size.Z,size.Y/2,x)
			part.Parent = model
			
			z = z + size.Z + gap
		end

		z = 0
		x = x + size.X + gap
	end

	model.Name = "block"
	model.Parent = workspace
	part.Transparency = 1
	part.Anchored = true
	part.CFrame = CFrame.new(model:GetBoundingBox().Position)
	part.CanCollide = false
	part.Name = "root"
	part.Parent = model
	model.PrimaryPart = part

	return model
end

for column = 1,5 do
	local hold

	for row = 1,5 do
		local block = createblock()
		local size2 = block:GetExtentsSize()

		hold = size2
		block:SetPrimaryPartCFrame(block.PrimaryPart.CFrame + Vector3.new(z2+size2.Z,0,x2))
		z2 = z2 + size2.Z + gap
	end

	print(z2,x2, "column "..column)

	x = 0
	z = 0
	z2 = 0
	x2 = x2 + hold.X + gap
end

and the output of the code from the print statement is this

  • 125 0 column 1
  • 125 25 column 2
  • 125 50 column 3
  • 125 75 column 4
  • 125 100 column 5

3 comments

0

also the pictures might not load

0

Edit: Made the images hyperlinks instead

0

also i think its something to do with the z axis, also i mixed up the x and z variables lol but ill fix that later