Labeling uis using range

how would I label uis using range? basically, say I have a number range 1-24 and I want to label each one of my 24 buttons from 1-24. how would I do that?

1 Like

If I understood correctly:

for i,v in ipairs(buttons:GetChildren()) -- Set buttons to the directory that you store your buttons in
    v.Text = v.Name -- Assuming each button is the number it needs to display
end

If this isn’t what you’re looking for, please elaborate.

1 Like

so lets say I have 24 buttons and my number range was 1-24, I would want it to set the text of each button from 1-24 so first button would be 1 second would be 2, and so on

1 Like

How are the buttons placed? Have you manually placed them or used UIGridLayout? How do you decide which button to name what?

1 Like

its in a uilistlayout so it will name them chronologically to the layout

You could do this if you don’t already have a set order:

local ListFrame = game.StarterGui.ScreenGui.Frame

local Count = 0
for _,Button in ipairs(ListFrame:GetChildren()) do
	if not Button:IsA("TextButton") then continue end
	Count += 1
	
	Button.Text = Count
	Button.LayoutOrder = Count
end

Or this if they are already sorted using LayoutOrder:

local ListFrame = game.StarterGui.ScreenGui.Frame

local Buttons = {}
for _,Button in ipairs(ListFrame:GetChildren()) do
	if Button:IsA("TextButton") then table.insert(Buttons, Button) end
end

table.sort(Buttons, function(A, B)
	return A.LayoutOrder < B.LayoutOrder
end)

for Index,Button in ipairs(Buttons) do
	Button.Text = Index
end
1 Like