Using Global DataStores as Ordered Data Stores

Hello, I am currently creating a game which handles very large numbers. I know multiple solutions have been found and used and it is not that big of a deal. When I was asking for advice, @Runiros gave me the idea of using global datastores as ordered ones.

So how does it work? When you want to update the leaderboard, you firstly loop through every player. If the player is on the leaderboard we use UpdateAsync to update the player’s data and make sure it doesn’t get overridden. If there are less than the amount of desired records, lets say 10, we just add the player in the leaderboard. Then we do another check, if the player’s data is bigger than the lowest value on the datastore, we remove the lowest one and replace it with the player’s. In this way we add the player on the leaderboard. This method has been used in a game before and it used to work perfectly well.

This is very useful as it is light-weighted, allows for use of libraries such as BigNum, there is also support for doubles. I scripted something like this so you can get an idea: Alternative Ordered DataStore - Roblox. It is uncopylocked so feel free to take a look at it. I’d love to hear your opinions :slightly_smiling_face:

2 Likes

If you want to order it in a data store to use for global leaderboards, use OrderedDataStores. OrderedDataStores and GlobalDataStores are the exact same thing, except for 2 things. One is that is can only store positive integers, and he other is that it has an extra method called GetSortedAsync(), which returns a DataStorePages. What you are doing right now would be much simpler with OrderedDataStores, and would only take one GetSortedAsync() call. OrderedDataStores have the same functions as GlobalDataStores as well as the additional GetSortedAsync() (though I would store an OrderedDataStore for the stuff that need to be shown on global leaderboards and only use one GlobalDataStore for managing data stores). Overall, I would recommend just using OrderedDataStores. Now comes the problem of using doubles, maybe this method would be good for doubles, but I would recommend OrderedDataStores if you aren’t using doubles.

1 Like

I just wanted to hear some opinions on that, not really planning on using it on my game. I am currently sticking to this method for storing numbers over 9.22 quadrillion, that is ODS limit. I don’t think doubles are really a problem in datastores as you can round the number before putting it on the datastore or just turn it into an integer and then convert i back to a decimal. So before you store 1.234 you multiply it by 1000 then divide it by 1000 back. Just thought I’d share this interesting work around.