Unfortunately, dictionaries (where the indexes of the table are anything but integral/numbers) cannot be sorted.
An alternative is to either write a function to copy all of the dictionary’s contents as indexes instead, or to make the name of the rank an additional field of the table object itself, which may ruin convenience a tad.
First option if you’re interested in that:
local function copyDictionaryAsTable()
local tab = {}
for rankName, rankData in pairs(Ranks) do
rankData.Rank = rankName --//Add reference to whatever the rank name is.
table.insert(tab, rankData)
end
return tab
end
local sortedRanks = copyDictionaryAsTable()
--//run sorting algorithm now
local Ranks = {
{
Name = "Newbie"
RequiredPoints = 0,
Color = Color3.fromRGB(39, 255, 140)
},
{
Name = "Pro"
RequiredPoints = 100,
Color = Color3.fromRGB(39, 255, 140)
},
{
Name = "God"
RequiredPoints = 5000,
Color = Color3.fromRGB(39, 255, 140)
},
}
for i, rank in ipairs(Ranks) do
print(rank.Name, rank.RequiredPoints, rank.Color)
end
if you create your table like this then you can loop the ranks in order without the need to sort them
Yer also the words newbie pro god are kinda useless as keys he would be better just using the keys 1 2 and 3 from the normal array and just save the players rank as numbers in the datastore if that’s what he is doing