How can i make a global statistics system that can bypass or atleast go over the issue of the 4mb per key limit

I have a new game, Beach Soccer. so far its doing really well but it has a problem.
I have a global statistics system that displays the top 50 of for example, goals, saves, etc

I got the issue where there is a limit of 4mb per key meaning i cannot just save all players data under one key, retrieve it and sort the statistics.

I switched to firebase and instantly got rate limited after 2-3 days on downloads

And i found something about :Getsortedkeysasync on roblox datastore but chatgpt is saying that its not optimal to get every key page and could cause a rate limit.

So what can i do? and also i plan to go from firebase to roblox datastore again as it seems it increases my storage as my game gets bigger which is way better than having to pay for firebase

1 Like

You’re going to want to look into OrderedDataStore | Documentation - Roblox Creator Hub.

They behave like regular Roblox datastores, except you must store integers in it (since you’re ranking goals and saves, those are integers and are compatible).
You’ll use the :GetSortedAsync() and will have to deal with a page system too (not too difficult to go through if you understand the documentation).

If you worry about rate limits, this means you call too often the functions. I suggest only making 1 call per minute per server, but you can change it depending on your game’s statistics, viewable in Roblox’ Create section (Creator Hub). And for the amount of values visible on your leaderboard, you could also limit them to only the 200 best players or something like that.

Let me know if you need specific help on code or something else!

2 Likes

So wait, with this i can just store integer only values and get keys by the highest or lowest? is there any limit such as 4mb like regular keys?

I’m not sure, you would have to check limits, but with regular datastores, it’s 4mb per keys (each key should belong to a different player anyways, not every player in a single key) with a limit of 100mb for the datastore, with a certain mb bonus per lifetime player.
Also you’re only storing in integer values, which would hold a very minimal amount of space, you should harly reach 10kb per player, so knowing it’s about 4mb of space in a datastore for each player, that’s a huge amount of data.

The issue is mainly the fact you store every player’s data in a single key, you should consider creating new keys unique for each player (using their UserID for example).

issue is how would i display the data on statistics till i get the keys? and seeing as the only method can get rate limited considering from firebase i seem to have over 10000 registered players

i also had another idea to just make seperate datastores for goals, assists, etc
had chatgpt calculate it, and 200,000 unique players would be needed before i hit the 4mb mark
and even then i reset stat data every month i dont keep alltime so that shouldnt be a issue

also apologies for the yap i just realized its 4mb per key and ordereddatastore stores everything in seperate keys

Make sure every player’s data does not reside in a single key…
You will need a script to read through that key and assign the data across keys for each player. And don’t worry about rate limit, requests get queued and throw a warning that you can follow in Creator Hub.
When the leaderboard hasn’t loaded yet, you can add a loading screen on it instead while they’re loading too.

If you are reaching the 4MB limit the problem definitely lies within how you are handling data

i mean i did state earlier, that there are over 10,000 registered players so reaching 4mb was easy
either way the solution provided that he gave me worked

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