Ordered DataStore with multiple values

So I want to make a global leaderboard, that shows the top (or bottom) 100 players, and you can choose to order it by individual playerstats, attached screenshot for reference:

My problem is I’m not sure how I would get the ordered data except for the one the player wants to order by (using the little arrows next to stats)

Server Code:

local DataStoreService = game:GetService("DataStoreService")

local GetOrderedGlobalStats = Rep.Functions.GetOrderedGlobalStats --Client to Server function to get ordered leaderboard

local DSV = "A_V22"
local DSV_Global = "GLOBAL1"

GetOrderedGlobalStats.OnServerInvoke = function(Player,Timespan,Stat,Ascending)--Player, which timespan the data is from (currently only "Alltime" exists),the stat the player is requesting to view highest/lowest of, top or bottom 100
    local GlobalDS = DataStoreService:GetOrderedDataStore(DSV_Global..Timespan..Stat) --"GLOBAL1AlltimeScore" in this case
    local PageSize = 100 --Getting top 100 players
    local Pages = GlobalDS:GetSortedAsync(Ascending, PageSize)
    return Pages:GetCurrentPage()
end

Client Script:

local GetOrderedGlobalStats = Rep.Functions.GetOrderedGlobalStats --Client to Server function to get ordered leaderboard

local LBG = GetOrderedGlobalStats:InvokeServer("Alltime","Score",false)
for i,v in pairs(LBG) do
	print(i,v) 
end

The problem here is that by doing this I am only getting back the Score stats, and cannot display the other stats in the leaderboard since they are not sent back by the server, however I want them, but I don’t know how I would go about doing that, without sending all the different Ordered DataStores back and doing a lot of loops which might hurt performance.
Note: This is the first time I have used Ordered Data Stores

1 Like

Impossible. An OrderedDataStore only takes a single positive integer. Ordering leaderboards like this would probably require you to create your own database server where you can store these results, order them and then send them around for use.

If you wanted to use OrderedDataStores specifically, you’d run into needing to use a new OrderedDataStore for every ordering of a player’s stats which really doesn’t sound great. You’d barely fit in the limits with a 5 + (players * 2) limit of GetSortedAsync requests as well. The problem with this though is that you can’t guarantee all leaderboard OrderedDataStores will be updated as in when necessary and some players might be missing from the DataStore if they don’t log in.

Something that may interest you as a future prospect is the RDC 2020 engineering keynote which discussed future upgrades to DataStores. One of the items on the roadmap was the ability to iterate through your DataStores. This may make creating leaderboards a little easier.

Video and timestamp are below.

5 Likes

That’s unfortunate. Thanks for letting me know. The timestamped part of the video indeed does seem interesting!

1 Like