How to make a global leaderboard?

I am wanting to make a Global Leaderboard for my game, for the most “cookies baked” which is a number value. I am wanting to display the top 50 players for this statistic.

I’ve already tried looking at tutorials, free models and the documentation however they are all setup for the datastore only having one value, while my datastore is setup in a table like this:

{
        Cookies = 0,
        Coins = 0,
        Gems = 0,
        Inventory = {
            EquippedTool = equippedTool,
            OwnedTools = ownedToolsTable,
            EquippedRank = equippedRank,
            OwnedRanks = ownedRanksTable,
            EquippedDNA = equippedDNA,
            OwnedDNAs = ownedDNAsTable,
        },
        Statistics = {
            TotalCookies = 0,
            TotalCoins = 0,
            TotalGems = 0,
            TotalEggs = 0,
            Playtime = 0,
        },
        Rewards = {
            DailyReward = 0,
            GroupReward = 0,
        },
    }

How would I be able to just get the top 50 players globally for the Statistics.TotalCookies value, with the datastore “A - Testing”, and keys being “Key_USERID”?

I don’t need help creating the GUI or anything, I just want to be able to get the top 50 players for that value, and the table of their datastore above.

You can only save a single integer value with ordered data stores. Getting specific entries in order from an array is not supported functionality so you would probably have to move cookies baked from your normal data store and use a separate ordered data store to save this one value. It isn’t ideal but there isn’t any other way without using a third-party service.

2 Likes

Hm, I will probably just set it up so it is still in the normal datastore but on a certain interval it updates on the leaderboard datastore then. Thanks for your help!

1 Like

I wouldn’t move ‘cookies baked’ as much as copy it over to an ordered datastore every once in a while. Moving it would make reading data harder in the long run. Beat me to it! lol

Extract the value from the table, and save only that value in the ordereddatastore.
Do this for every player in your game every so often.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.