function getCellPositionsFromPlank(plankModel)
local primaryPart = plankModel.PrimaryPart
if not primaryPart then
warn("Plank model does not have a PrimaryPart: ".. plankModel.Name)
return {}
end
local positions = {}
local partCFrame = primaryPart.CFrame
local partSize = primaryPart.Size
-- 1. Determine the orientation and length of the plank.
local numCells
local stepDirection
if partSize.X > partSize.Z then
-- X-Oriented plank (e.g., Size is 48x16x16)
numCells = math.round(partSize.X / CELL_SIZE)
stepDirection = partCFrame.RightVector
else
-- Z-Oriented plank (e.g., Size is 16x16x48)
numCells = math.round(partSize.Z / CELL_SIZE)
stepDirection = partCFrame.LookVector
end
-- 2. Calculate the center of the VERY FIRST cell.
local totalSpan = (numCells - 1) * CELL_SIZE
local firstCellCenter = partCFrame.Position - (stepDirection * (totalSpan / 2))
-- 3. Loop and calculate the center of each subsequent cell.
for i = 0, numCells - 1 do
local cellCenter = firstCellCenter + (stepDirection * (i * CELL_SIZE))
table.insert(positions, cellCenter)
end
print(#positions)
return positions
end
Each plank is either 48x16x16 or 16x16x48 each “cell” is a cube that is the product of 1/3 of the plank. So really just 1/3 of the plank which is always 16x16x16. I want each cell position in a block. to place my little coin. However when running this function it somtines returns 1 position instead of 3.
meaning it doesnt return all cell positions sometimes only the center. How can I fix this?