You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want my ordered stores to stop throttling, I know what lines of code are causing it.
What is the issue? Include screenshots / videos if possible!
I’ve tried slowing down the rate of requests sent, but the problem is. Even slowing down the rate by 1 second causes the leaderboards to take too long to load. Currently my game has 39 keys saved. If my playerbase increases it would take even longer. That’s why I have no cooldown in my code, I was wondering if there was another way to stop the throttling.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have not found anything related to my issue.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- Small part of the code where I believe issue arises
BoardNPC.Head.BillboardGui.TextLabel.Text = "Loading leaderboards..."
local worked, ListedPages = pcall(function()
return DataStore:ListKeysAsync("", 0, "", true)
end)
if worked then
local ListedPage = ListedPages:GetCurrentPage()
for _, keyinstance in ListedPage do
if not string.find(keyinstance.KeyName,"-") then
-- I check this just to stop the studio bots from adding their data along.
local success, errormessage = pcall(function()
-- Fairly certain this is where the issue occurs, I have 39 keys so thse requests
are sent 39 times all in the span of a second or so.
--]]
local Data = DataStore:GetAsync(keyinstance.KeyName)
RobuxStore:SetAsync(keyinstance.KeyName, Data.DonatedBux)
RobuxSpentStore:SetAsync(keyinstance.KeyName, Data.SpentBux)
TimeStore:SetAsync(keyinstance.KeyName, Data.Time)
end)
if not success then
BoardNPC.Head.BillboardGui.TextLabel.Text = "Leaderboards failed to load! Retrying..."
end
end
end
else
BoardNPC.Head.BillboardGui.TextLabel.Text = "Leaderboards failed to load! Retrying..."
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Can you please elaborate on why you are needing to update 3 datastores, 39 times, each leaderboard refresh? That seems completely unneccessary and I assume there would be a better solution than what you are trying.
So 3 datastores because orderedstores can’t hold arrays or dictionaries, I need to update them to copy over the new data the player has in the server because my normal datastore contains all the values. And 39 times because the original data everyone has is in a regular datastore, and regular datastores are unordered so I’d need to check every single key.
I have an idea of a solution however, simply I copy over the data value from the regular store to its respective orderedstore once in studio. That way I don’t need to send and setasync/getasync requests anymore.
I don’t know what you have in listedpages etc ofc but I’ll just say incase like if you’re fetching all player data individually like playerid…“currency” and playerid…“xp” etc then if you combine them like making playerid…“playerdata” = “?currency&123?xp&456” then use string.split to read the data? Hopefully this can help
What I would probably do is have one key per leaderboard, that is updated using :UpdateAsync(), and retrieved using :GetAsync(). Subsequent calls can be made every some amount of time to update the leaderboard’s display
How it works is, the server does an initial :GetAsync() call to get the data. As players are playing, compare their stats against, the server’s leaderboard stats. If a player has stats good enough to make it on the leaderboard, that’s when the server will update the datastore using :UpdateAsync(). In the update async function, compare the player’s stats with the existing stats (and make sure to remove the existing field of that player if it exists). Insert that player along with its stats in the array, at its position in the leaderboard. Cap the array to a couple hundreds by removing the entries past index XXX
This method should be quite cheap on the datastore budget. The main downside is that there is a game wide limit on how often you can use UpdateAsync on a single key (from multiple servers) due to how update async works. Just don’t call it too often for leaderboard players, and if it fails, don’t retry, let it update next time
Currently I have 45 keys in total for my game. So all I’m going to do is simply copy over all the data from my regular store to the orderedstores. And then I won’t have to copy over ever again.
This is my solution to my problem, if it works I’ll mark this as the solution.