I put your code under eachother in order of execution, to try to understand it. But some parts don’t add up for me and might be the cause for your problem. (i’ve added ? where that happens)
-- here you create the array
local array = createArray(15,15,0)
-- it is a 2d jagged array where every value is 0
-- example:
[
[0,0,0,0],
[0,0,0,0],
[0,0,0,0],
[0,0,0,0]
]
-- every array is a row and every 0 is a column
-- now you use this array to create breakables and unbreakables
function breakables(array)
-- j is the index of the row
-- v is the actual array on that row
for j, v in pairs(array) do
-- half of the rows will become unbreakable
if j % 2 == 1 then
tileType:Unbreakable(array,j) -- ? array is the entire map, j is the current row
-- every other row has a 75% of being breakable, otherwise staying empty
elseif math.random() > .25 then
tileType:Breakable(array,j) -- ? array is the entire map, j is the current row
end
end
end
function tileType:Unbreakable(array,num)
-- tabBlocks is an empty table/array
if tabBlocks[num] then -- if there is a value stored at the current row in tabBlocks
local pos = tabBlocks[num]
local block= unBreakable:Clone() -- ? then create a single unbreakable for the entire row
block.Parent = fileBlocks:WaitForChild("Unbreakables")
block.Position = pos + Vector3.new(0,4,0)
end
-- i is the index of the row
-- v is the actual array on that row
for i, v in pairs(array) do
-- ?(_ should only be used when you don't use the variable)
-- _ is the index of the column in v
-- j is the value of the column in v (0 by default)
for _, j in pairs(v) do
-- ? if there is a value at the index of the column divided by 2 in tabBlocks
if tabBlocks[_/2] then
local pos = tabBlocks[num] -- read the value at the current row in tabBlocks
local block= unBreakable:Clone() -- then create an unbreakable
block.Parent = fileBlocks:WaitForChild("Unbreakables")
block.Position = pos + Vector3.new(4*_,4,0) -- with position being the index of the column in v multiplied by 4 for the x axis
-- ?(but the z axis is always 0, so blocks can only be next to eachother, not above eachother)
end
end
end
end
tabBlocks
is read using both the column index/2 and the row index, I don’t know what it’s supposed to do.
Also as far as i can tell values in array
are never changed nor values in tabBlocks
.
So the 2 times that you do local pos = tabBlocks[num]
pos
is always 0 or nil