What solutions have you tried so far?
I searched all over the Devforum
One person did say
“You just gotta divide the cash by the amount of cash that it takes to make one layer, use the remainder to calculate how many smaller stacks are on top, until you’ve used all of it.” – It would have been helpful if the user provided an example.
can u like provide a bit more explanation of what u want to achieve? (like i mean i know its a cash stacking system, but in which case u want to use this)
Lets say that 100 bucks is one cash instance, 12 of them would fill up a layer, so just do something like this:
local layers = 0
local rows = 4 -- 4 rows of cash available in the stack
local maxStack = 12
local divider = 100 -- how much cash is 1 instance
local startPos = cashStackStartingPosition
local nextLayerPos = nextLayerFirstStackPosition
local nextRowPos = nextRowFirstStackPosition
-- substitute these 3 values with the positions in your stack
local function StackControl(earnedCash) -- call it when you want to update the stack
local amount = math.round(earnedCash / divider)
local prev -- prev is gonna be set to the previous instance in the loop to calculate the position of the next one
for i = 1, amount do
local newPos
if i % maxStack then -- if the layer is full
-- go to the first slot of the next layer
newPos = nextLayerPos
elseif i % rows then -- if the row is full
-- go to the first slot of the next row
newPos = nextRowPos
else
if i == 1 then
newPos = startPos.Position
else
newPos = prev.Position + Vector3.new(3,0,0) -- add the offset of the new model
end
end
local part = CashModel:Clone()
part.Position = newPos
part.Parent = workspace
prev = part
end
end