I’d like to have a place to store userID, stage (string), difficulty (string) and time (NumberValue) for the purposes of creating multiple billboard leaderboards that would display top 100 data in ascending order.
I do not have much exposure with datastores but from my understanding the GetSortedAsync() method can only return between 1 and 100 keys, and I need to be able to return 100 keys per each difficulty and stage (there are 3 difficulties and 6 stages, so 1800 keys)
I want to limit the amount of data fetching I do on the server and store it in local tables, however i’m uncertain how often this data should be refreshed in order to display accurate data without sacrificing much performance (ie task.delay(60) and then refresh data.)
I don’t know if I need to create 18 individual OrderedDataStores To achieve this or if all this data can be put into a single OrderedDataStore that can then be filtered by some string matching method (and probably re-order as the data will have mixed data)
I’m looking for a general approach to this, and if OrderedDataStore is even a viable service to house this data. Snippet of code here to illustrate a function residing in a module script that could be generating and retrieving data, although I haven’t delved much into the coding aspect of this as i’m uncertain on the approach:
local function sortAndReturnSpeedRunPersonalBestForTop100PlayersForGivenDifficulty(player, speedrunDifficulty) -- use a structured key system: <UserId>_<Stage>_<Difficulty> for saving (this function is not for saving) local speedRunPersonalBestForTop100PlayersForGivenDifficulty = {} local pages = speedRunDataStore:GetSortedAsync(true, 100) -- Ascending order for _, entry in pages:GetCurrentPage() do local key = entry.key -- name of the key, will be <UserId>_<Stage>_<Difficulty> local timeInMilliseconds = entry.value -- key's value, will store time in milliseconds as datastores cannot save decimals, so conversion is needed local timeInSeconds = timeInMilliseconds / 1000 -- Convert milliseconds to seconds local userId = tonumber(string.match(key, "^%d+")) -- Extract the UserId from the key local difficulty = string.match(key, "%w+$") -- Extract the difficulty from the key if difficulty == speedrunDifficulty then table.insert(speedRunPersonalBestForTop100PlayersForGivenDifficulty, {userId, stage, timeInSeconds}) end end return speedRunPersonalBestForTop100PlayersForGivenDifficulty end