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

How to position a Gui depending on the last element in a table?

I am trying to list about 10 Guis in a single line, sort of like a drop down menu, except in this case they don't disappear. It worked, but not exactly how it suppose to

ChallengeList is a table that store all the Guis that I added, if the table is empty than the first gui position would be 0, 3, 0, 3 and then it add up 23 from the last Gui inserted in the table ( 3 + 23 = 26)

There no errors, but what happening is that the first two Guis position become 0, 3, 0, 3 and the third one become 26 and so on. Anyone know exactly how I can solve this problem?

Gui.Position = (ChallengeList[#ChallengeList-1] ~= nil and ChallengeList[#ChallengeList-1].Position + UDim2.new(0, 0, 0, 23)) or (UDim2.new(0, 3, 0, 3) 

2 comments

0

Your question is confusing. Why do you care about that last item in the table? What makes the last thing special?

0

Well I care about the last item because the item that I am inserting into thable, position need to be based on the last item. Later in the script I am going to update the list , that why I need to store all the GUIs. By update I mean fix the positioning where they no spaces between the guis, after a gui disappear.

1 answer

If you have a list, then the nth element will just be at 3 + 23 * (n-1) y:

for i = 1, #list do
	-- label is your gui object
	label.Position = UDim2.new(0, 0, 0, (i - 1) * 23 + 3)
end

Alternatively, the first one is placed somewhere and the next is based on the previous:

local previous
for i = 1, #list do
	-- label is your gui object
	if previous then
		label.Position = previous.Position + UDim2.new(0, 0, 0, 23)
	else
		label.Position = UDim2.new(0, 0, 0, 3)
	end
	previous = label
end

The first one seems much simpler.

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