What do you want to achieve?
I want the leaderstats to sort my string values.
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.
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.
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