So I'm making a backpack script that uses buttons to represent items in the backpack. My problem is, after a player clicks on an item and places it and the button disappears, there is an empty spot between the remaining buttons, which causes other problems. I'm trying to make it so that when for example (if there are 5 buttons in a column) the third button is removed, buttons 4 and 5 move up to fill the missing space. I've attempted this but it seems like way to much code for something so seemingly simple. Here's what I've tried so far
function get_position()
local Ipack_tab = IFRAME:GetChildren()
local RANDOM = IFRAME:FindFirstChild()
local ONE = false
local TWO = false
local THREE = false
local FOUR = false
local FIVE = false
for index, child in pairs(Ipack_tab) do
if child.Position.X.Offset == 0 and child.Position.Y.Offset == 0 then ONE = true else ONE = false
if child.Position.X.Offset == 0 and child.Position.Y.Offset == 20 then TWO = true else TWO = false
if child.Position.X.Offset == 0 and child.Position.Y.Offset == 40 then THREE = true else THREE = false
if child.Position.X.Offset == 0 and child.Position.Y.Offset == 60 then FOUR = true else FOUR = false
if child.Position.X.Offset == 0 and child.Position.Y.Offset == 80 then FIVE = true else FIVE = false
end
end
end
end
end
if ONE == false then RANDOM.Position = UDim2.new(0, 0, 0, 0)
end
end
end
basically ONE, TWO, THREE, FOUR, and FIVE represent spots where the buttons can be, and if they're true then there's a button there and false if there isn't. but like I said this just seems inefficient and I'm stuck. Can anyone give me suggestions or ideas on how to solve this? thanks guys!

2 comments
but wouldn't this move all the buttons the same amount?
Only the ones that have a higher value than the deleted, but if that's not what you wanted, please elaborate.