How to sort player list by rank

I want to make a player list like in minecraft that sorts the lists by rank, which means the higher rank the higher you are on lb. And if 2 people have the same rank then they are sorted by alphabetic too.

Order (Highest to lowest)

  1. Owner
  2. Admin
  3. Moderator
  4. YouTuber
  5. MVP
  6. VIP
  7. Player

I assume you want to sort the lists in a UI frame (who would sort something people wouldn’t look at right?)

UIListLayout + LayoutOrder property in gui objects (less layoutOrder gets placed higher in the list)

but i want players to be sorted by rank if there are more than 1 people with same rank then it sorts them alphabetically too

Then you would have to implement custom sort logic
like,
dictionary[firstLetter] = additionalLayoutOrder
and leave some space for the letters
like,

local rankLayoutOrder = {Owner = 0
Admin = 100
Moderator = 200}

… and so on

local alphabetLayoutOrder = {"a" = 0,
"b" = 1,
"c" = 2,
"d" = 3,
-- up until Z, and numbers 0-9

and then in the “Clone List Template” function

local new = template:Clone()
local firstLetterLowered = string.lower(string.sub(playerName, 1, 1))
new.LayoutOrder = rankLayoutOrder[rank] + alphabetLayoutOrder[firstLetterLowered]