How to sort dictionary

I want to sort a dictionary into the order of total score. Quick example would be:

local Scores = {
	["Player1"] = 5,
	["Player2"] = 2,
	["Player3"] = 19,
	["Player4"] = 8,
}

function Sort(tbl)
	local SortedTable = table.sort(tbl, function(a, b)
		return a > b
	end)
	
	return SortedTable
end

print(Sort(Table))

print returns nil however. Basically, all the players scores would be assigned to their player, and I want the return table to ideally look as so

local Scores = {
	["Player1"] = {
        Rank = 3,
        Tags = 5,
    },
	["Player1"] = {
        Rank = 4,
        Tags = 2,
    },
	["Player3"] = {
        Rank = 1,
        Tags = 19,
    },
	["Player4"] = {
        Rank = 2,
        Tags = 8,
    },
}

-- How I do it
PlayerStats[Creator.Value] = {
	Rank = Sort(PlayerStats),
	Tags = 1
}

Dictionaries have no order. You have a couple of alternatives though. If you don’t need to get the values by key, you can just make it a list.

local Scores = {
    {Name = "Player1", Rank = 3, Tags = 5},
    {Name = "Player1 again", Rank = 4, Tags = 2}
}

If that’s not going to work for obvious reasons, keep a second table detailing the sort.

local ScoresOrder = {"Player1", "Player3", "Player4", "Player2"}
local Scores = {
    Player1 = {Rank = 3, Tags = 5},
    Player3 = {Rank = 1, Tags = 19},
    Player2 = {Rank = 4, Tags = 2},
    Player4 = {Rank = 2, Tags = 8}
}
local function SortScores()
    table.sort(ScoresOrder, function(a,b)
        return Scores[a].Rank > Scores[b].Rank
    end)
end
local function GetHighestRank()
    return Scores[ScoresOrder[1]].Rank
end

Also, I could be wrong on this, but I don’t think table.sort returns anything. I think SortedTable would be nil even if dictionaries could be sorted.