Ordered Datastore/ Alternatives

I am trying to create a global leaderboard for a game, however I cannot use an ordered datastore, as this stat (money) is located as such:
image
How can I get the top X players without iterating through over 500 thousand people? Is there a way to cache this somehow? The docs for ordered datastore says the keys need to be integers, which is out of the question.
My current idea is to make a duplicate datastore for money, but I’d rather not.

2 Likes

If you want to get the top players, you kinda have two options: go through all the data at once, or sort it. Sorting it would most likely involve using another datastore. There’s no magic way to sort data, and the most efficient way would to just use another datastore.

1 Like

That’s what I was trying to avoid, but I guess I’ll have to resort to that. Thanks.

Have the second, ordered datastore, and just mirror what is in the normal datastore for the money stat. Whenever you load the player’s data, you would get it from the normal datastore, but then for leaderboards, you would use the ordered datastore.

1 Like