Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to deal with GetAsync or SetAsync queue when saving data quickly?

Asked by
asadefa 55
5 years ago

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?

1
Save less often. DinozCreates 1070 — 5y
1
That'll be 5$ DinozCreates 1070 — 5y
1
And yes, you shouldn't be saving that often. User#25115 0 — 5y
View all comments (4 more)
1
What if I have to save less often? How can I make it slowly save it? asadefa 55 — 5y
1
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. DinozCreates 1070 — 5y
0
Save only when the player is leaving and after a gamepass purchase. Rheines 661 — 5y
0
Roblox keeps track of gamepass purchases, so i dont think thats relevent. I only save on leave or forced shutdown. DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by
seith14 206 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
I don't quite understand the plrs table part asadefa 55 — 5y
0
O it's just indexing I can explain more to you on my disc if you would like, Intellectual#6238 seith14 206 — 5y
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 seith14 206 — 5y
Ad

Answer this question