How to get the gui sort order

Capture
Is there a way to get the order of the gui order

Yes using UIList/UIGridLayout you can set in properties of each GuiObject its LayoutOrder.

but is there a way to get the order though like get a table of the order.

You are creating leaderboard right?

Please refere it more I dont completely understand you atm.

Ye, the thing is, that the screenshot wasn’t in a game, I just made the GUI for a example, but I need to label the places, and since the frames are listed with sort order already, I just want to go thought the order of the GUI and then get the places.

like this

local Number = 0
for i, v in pairs(Order) do
      Number = Number+1
      gui.place.text = Number
end

don’t mind the code is just a example and I hope you get the idea.

Okay so you can just do

local player = game:GetService("Players").LocalPlayer
local TextHandler = player.PlayerGui.ScreenGui.Frame
local Number = 0

for i,v in pairs(TextHandler:GetChildren()) do 
Number += 1
v.LayoutOrder = Number
end
2 Likes

done it, soz that took a while

Alright so you got it? If yes then good job!

1 Like

wait, I just need it to fit in with the rest of the code and test but I believe this works, thx

1 Like

Let me know If dont in PM.
i am glad that I help you ;).

1 Like

sorry but after some testing, it actually doesn’t work because the first time I tried, Player1 got more KO which made sense but it didn’t work when Player2 got more KO because the order that I loop though is in alphabetical order and is not in the KO order which is what I wish it loop though. The code you told me to try doesn’t change anything that much but thanks for the help so far.

You can combine this example with an UiListLayout

for i,v in pairs(Order) do
      local YourFrame = (your frame):Clone()
      YourFrame.TextLabel.Text = "bla bla bla"
end
1 Like

Sorry for late response you can just use Changed event to connect it with.

1 Like

I’m not trying to sort the UI objects in order, I’m trying to get the order.

oh ye, I forgot to tell you but the leaderboard is after game so the KO values wouldn’t change.

Oh got it can you please send me repro file so I can look into it?

1 Like

its ok, it works now, I just did
local KOs = {}

	for i, v in pairs(game.Players:GetChildren()) do
		table.insert(KOs,v.KO.Value)
	end

	local sortedTable = table.sort(KOs,
		function(a,b)
			return a > b
		end
	)

for index, player in pairs(game.Players:GetChildren()) do
	 for i, v in pairs(KOs) do
		if player.KO.Value == v then
		       CloneFrame.Place.Text = i
		end
	 end

` end
thanks for helping me

1 Like

Glad that you fixed it good job!

1 Like