How to sort the leaderstats with strings?

  1. What do you want to achieve?
    I want the leaderstats to sort my string values.

  2. What is the issue?
    I’m making a system where you can rank up, and it’ll change your rank in the leaderstats with a string value. But the thing is that the leaderstat isn’t sorting strings very well. As you can see in the screen shot below, player 1 with the “Noob” rank is higher than someone with the “Beginner” rank, which isn’t supposed to be the case.

  3. What solutions have you tried so far?
    I’ve been checking on the dev forum but I don’t find anything related to my issue.

This is my simple leaderstats: (I know i’m not sorting anything, would just like to know how to do so)

	local rankValue = Instance.new("StringValue")
	rankValue.Name = "Rank"
	rankValue.Value = "Noob"
	rankValue.Parent = leaderstats

You could use an array that has number as index, and the rank as the value.

local Ranks = {
  "Hacker",
  "Pro",
  "Noob"
}

local function RankToIndex(Rank)
 for Index, Value in Ranks do
   if Value == Rank then return index end
 end

 return nil
end

You can save a number (index of rank from Ranks array) and use RankToIndex and Ranks[PlayerRankDataValue] to set and get their rank.

As for leaderstats sorting this forum might have something

Well what I would do, is I would have a tier list of all the ranks, ordered by importance, something like this:

local Ranks = {
	Noob = 1,
	Soldier = 2,
	Prince = 3,
	Admiral = 4,
	King = 5,
}

Then when they rank up, you could do:

for i, rank in Ranks do
	if tostring(i) == player.leaderstats.Rank.Value then
		rank += 1
		local newRankName = i + 1
		player.leaderstats.Rank.Value = tostring(newRankName)
	end
end

When you want to update the rank.