Leaderboard "Priority" value sorting does not work

Upon attempting to sort a game’s leaderboard to show staff (higher group roles) to appear towards the bottom of the leaderboard using lower Priority values, I discovered that the feature does not work.

One possibility is that the sorting is not working at all as the leaderboard appears to be sorted based on the reverse alphabetical order of the rank names, which is the default behavior.

Video:

Documentation:

Script:

local GroupID = 5613578
local CharHide = 0 --Amount of characters from the beginning to hide
game:GetService('Players').PlayerAdded:Connect(function(p)
	local ls = Instance.new('IntValue', p)
	ls.Name = 'leaderstats'
	local rank = Instance.new('StringValue', ls)
	rank.Name = 'Rank'
	rank.Value = 'Guest'
	if p:IsInGroup(GroupID) then
		local xrole = p:GetRoleInGroup(GroupID)
		if string.len(xrole) <= CharHide then
			warn('[GroupLeaderboard] Attempted to hide more characters than role has; using default name')
			rank.Value = xrole
		else
			local role = string.sub(xrole, CharHide)
			rank.Value = role
		end
	end
	local priority = Instance.new('NumberValue', rank)
	priority.Name = 'Priority'
	priority.Value = 255 - p:GetRankInGroup(GroupID)
end)

Expected behavior

The leaderboard should place players with a higher Priority value at a higher position than those with a lower Priority value.

2 Likes

Thanks for the report! I filed a ticket in our internal database.

1 Like

Hi, any updates to my bug report?

Unfortunately, this isn’t what the value is intended to do. The Priority IntValue determines the order of which the stats should be ordered relative to each other in the columns of the leaderboard, not the order to sort the players in. For example, you could have three values, ‘Gems’, ‘XP’ and ‘Cash’; and wish for ‘Gems’ to be displayed first and ‘XP’ displayed second regardless of the order of creation, Priority would help in this case.

In order to sort the players like you want to in this example; you’ll need to make use of invisible whitespace characters alike in this tutorial

3 Likes

The Priority value sorts the leaderstats value, which is what I am trying to do in this case.

If a new sorting feature is added, then great. But as I found out long ago, you have to write your own sorting function. :expressionless:

The Priority value doesn’t do any player sorting to my knowledge. It just sorts the horizontal ‘value’ columns relative to each other; the vertical order of players in the player list is still just based off the alphabetical / numeric sorting of the first column in the list (and then any subsequent tie-breaker columns). Since you only have one value column, the Priority value isn’t going to have an effect in this case.

To sort the player entries themselves, you will need to make use of one of the workarounds in the tutorial I mentioned since the Priority value doesn’t handle custom player sorting by itself, unfortunately.

How do you do that? The leaderboard barely has any customization as far as I know.

Wait, so they added a value to sort the columns… even though there are a whopping total of 3 columns that are normally sorted by the order in which they’re made? Seems pretty useless to me.

You use a sort hack. My memory is a little fuzzy because I had to deal with this also years ago, but basically certain characters like a space for example, don’t show up in the leaderboard and they can be used as a “pseudo” sort. Everything sorts vertically & alpha-numerically from the first column, so if you wanted the first column to be the “wins” for example, but you wanted to actually sort the rows by the second column of “points” then the leaderboard data would have to be written in a way that extra spaces are throw into the data part of the first column to make it sort the way you want it to. Basically, you keep chucking in extra spaces to make it manually sort the way you determine what sorting order it should be. I can’t remember which direction, but like add 1 space for 1st, 2 spaces for 2nd, and on and on until it sorts exactly like you want it. You end up with some really crazy strings when you have a lot of players, but it works and all the extra spaces don’t show on the leaderboard. :thinking:

Interesting. Thanks, I’ll try it!