How can I manage quickly using Database: GetAsync or Database: SetAsync without getting errors about my queue being full. Usually, if it is full, it would discard the changes. This would be a problem when saving data for obvious reasons. What is the best way to handle this?
✓ ANSWER ACCEPTED
How to deal with GetAsync or SetAsync queue when saving data quickly?
1 answer
✓ Accepted answer
This should work, It's added to a indexed table then saves when left. I've never had a problem with this.
I don't believe you will need a queue but if you do you could use 60 + numPlayers × 10
link to datastore Errors and Limits: https://developer.roblox.com/articles/Datastore-Errors
local plrs = {} -- table that players get indexed into
local datastore = game:GetService('DataStoreService'):GetDataStore('PlrData')
local cansave = true
game.Players.PlayerAdded:Connect(function(plr)
local suc,data = pcall(function ()
return datastore:GetAsync(plr.UserId)
end)
if suc and data then
plrs[plr]={['Gold']=data.Gold}--indexed table
elseif suc then
plrs[plr]={['Gold']=0}
end
end)
function save(plr)
datastore:SetAsync(plr.UserId,plrs[plr])
cansave = true
end
game.Players.PlayerRemoving:Connect(function(plr)
if cansave then
cansave = false
save(plr)
end
end)
game:BindToClose(function() -- saves everyone's data when game closes
for _, plr in pairs(game.Players:GetPlayers()) do
if cansave then
cansave = false
save(plr)
end
end
end)
3 comments
0
I don't quite understand the plrs table part
0
O it's just indexing I can explain more to you on my disc if you would like, Intellectual#6238
0
It's basically inserting something into the table, but really it's not inserting at all. It's a fake table but can store stuff inside them
This discussion is preserved as it was. New answers, comments, and votes are closed.

8 comments
Save less often.
That'll be 5$
https://developer.roblox.com/api-reference/function/DataStoreService/GetRequestBudgetForRequestType
And yes, you shouldn't be saving that often.
What if I have to save less often? How can I make it slowly save it?
To help you fix your datastore we need to see your datastore. Hard to know what you're doing wrong without knowing what you're doing.
Save only when the player is leaving and after a gamepass purchase.
Roblox keeps track of gamepass purchases, so i dont think thats relevent. I only save on leave or forced shutdown.