Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a better way to get these buttons flush up against each other?

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!

1 answer

An easy solution that I can think of is to move the buttons of higher value to the left by a certain increment, which should be the length of the buttons.

Example:

buttons = {one,two,three,four,five} -- Empty variables, but I hope you get the idea

for i = 1,5 do
	if buttons[i] > deletedButton then
		buttons[i]:MoveToLeft()
	end
end

I hope this logical explanation will help.

2 comments

0

but wouldn't this move all the buttons the same amount?

0

Only the ones that have a higher value than the deleted, but if that's not what you wanted, please elaborate.

This discussion is preserved as it was. New answers, comments, and votes are closed.