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