Hey there!
I’ve been trying to create a system to make a grid of blocks, but it’s not generating it how I would like it to. Of course I want it to be a grid, but it just makes this:
https://streamable.com/c0pi7m
Here is the code I am using to make the grid:
local piece
local lastPiece
local newPiece
local spacingSpace = CFrame.new(6, 0, 0)
local spacingRow = CFrame.new(0, 0, 6)
local onRow = 1
local onSpace = 1
local spaceMax = 10
local rowMax = 4
local function CreateGrid()
for i = 1,spaceMax do
wait(.1)
if not newPiece then
piece = game.ReplicatedStorage:WaitForChild("GridPiece"):Clone()
else
piece = newPiece:Clone()
end
if lastPiece and onRow == 1 then
piece.Main.CFrame = lastPiece.Main.CFrame * spacingSpace
piece.Border.CFrame = lastPiece.Border.CFrame * spacingSpace
piece.Bottom.CFrame = lastPiece.Bottom.CFrame * spacingSpace
piece.GridHumanoidPosition.CFrame = lastPiece.GridHumanoidPosition.CFrame * spacingSpace
end
piece.Name = "GridPieceR"..tostring(onRow).."S"..tostring(onSpace)
lastPiece = piece
piece.Parent = workspace:WaitForChild("GridStorage")
onSpace = onSpace + 1
if onSpace == spaceMax and onRow < rowMax then
onRow = onRow + 1
onSpace = 1
newPiece = game.ReplicatedStorage:WaitForChild("GridPiece"):Clone()
newPiece.Main.CFrame = workspace.GridStorage["GridPieceR"..tostring(onRow-1).."S"..tostring(onSpace)].Main.CFrame * spacingRow
newPiece.Border.CFrame = workspace.GridStorage["GridPieceR"..tostring(onRow-1).."S"..tostring(onSpace)].Border.CFrame * spacingRow
newPiece.Bottom.CFrame = workspace.GridStorage["GridPieceR"..tostring(onRow-1).."S"..tostring(onSpace)].Bottom.CFrame * spacingRow
newPiece.GridHumanoidPosition.CFrame = workspace.GridStorage["GridPieceR"..tostring(onRow-1).."S"..tostring(onSpace)].GridHumanoidPosition.CFrame * spacingRow
newPiece.Parent = game.ReplicatedStorage
CreateGrid()
lastPiece = nil
end
end
end
CreateGrid()
Any help is greatly appreciated!