Example scenario:
I have a “Speedrunning” game which contains about 100 maps and I want to create a leaderboard which obtains the top 10 best speedrun scores for each map.
The script I’ve tried is:
local DataStoreService = game:GetService("DataStoreService")
local storage = game:GetService("ReplicatedStorage")
local allmaps = storage.Maps:GetChildren() --They're all folders, don't worry.
for i,map in pairs(allmaps) do
local databoard = DataStoreService:GetOrderedDataStore(map.Name)
local pages = databoard:GetSortedAsync(false, 10) --Get top 10 score descending.
local data = pages:GetCurrentPage()
end
Something easier to do would be to make a table of all the current maps (which you already did) and have another datastore which is JSON encoded that has all that info.
Can you make an example?
and also it needs to be sorted into a top 10 that’s why I use OrderedDataStore instead of regular DataStore to store map tables.
I see that. A way you can do this is by placing everything in one datastore with seperate tables. Doing the math, each table (encoded with json) will have about some amount of letters inside of it. A normal datastore can hold about 26-260k (i forgot, but i think 260k) letters. Knowing this, we could do the math and estimate that there will be about 290 to 400 letters inside of each datastore. If we were to multiply this by 100 (your map count), we would get something in the 20k to 40k area. This fits the datastore’s len count (still, i don’t know if it’s 26 or 260k), which gives us a fit. Now, if you were to add tables inside of an encoded table, you’d get something like this:
local HTTPService = game:GetService("HTTPService")
local Maps = {["map1"] = {["blah"] = "player"}, ["map2"] = {"yeah", 123}}
local Encoded = HTTPService:JSONEncode(Maps)
This JSON encoded table holds the details of each map. If you want to make your encoded string back into a table, you can do JSONDecode. Since your maps are inside of one table, you can’t really use GetOrderedDataStore here (sorry about that), so using ipairs would be the greater solution to this.
It’s 5 AM and I haven’t slept, so if something is not matching up with what you want, then I apologize for that.
I understand your explanation as well as the script. But the problem will still continues because there’s still no solution to sorting players’ scores.
Well, if there hadn’t been any cooldown to datastores then the problem wouldn’t have occured in the first place.
You can use table.sort or ipairs, like I have said. ipairs gets the players lined up how they should be, unlike pairs and next. You can also use a for loop for this (would have to make the tables in numerical order instead of string names, though!).