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

[UNSOLVED] How do I stop game from freezing when I end game to save data?

Asked by 2 years ago
Edited 2 years ago

I have a script that saves data of a player before the player leaves the game. Sadly, this is causing the player to lag/freeze. (I have tested when disabling/commenting this script the game runs smoothly when exiting)

I also receive this warning message:

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 96373787

The script:

game.OnClose = function()
    for i, v in pairs(playerdata) do
        datastore:SetAsync(i, v)
    end
end

I have also tried (same problems/warnings/freezing):

game.Players.PlayerRemoving:Connect(function(player)
    for i, v in pairs(playerdata) do
        datastore:SetAsync(i, v)
    end
end)

3 answers

Log in to vote
0
Answered by 2 years ago

the warnings aren't important, just general info about datastore. However, I think you may want to try adding a wait(0.01) to the loop, like this:

game.OnClose = function()
        for i, v in pairs(playerdata) do
            datastore:SetAsync(i, v)
        wait(0.01)
        end
    end
0
I didn't put it in the post, but I had already tried that, the problem still persists. hattim00 80 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Hello.

There are limits applied to the data store model. If an experience exceeds these limits, the service will automatically throttle the experience’s data store usage, causing requests to be placed in a queue.

Cool Downs

Request Per Minute


Get

GetAsync() -- 60 + numPlayers × 10


Set

SetAsync() -- 60 + numPlayers × 10

IncrementAsync() -- 60 + numPlayers × 10

UpdateAsync() -- 60 + numPlayers × 10

RemoveAsync() -- 60 + numPlayers × 10


Get Sorted

GetSortedAsync() -- 5 + numPlayers × 2

Get Version

GetVersionAsync() -- 5 + numPlayers × 2


List

ListDataStoresAsync() -- 5 + numPlayers × 2

ListKeysAsync() -- 5 + numPlayers × 2

ListVersionsAsync() -- 5 + numPlayers × 2


Remove

RemoveVersionAsync() -- 5 + numPlayers × 2


Rewriting Data Or saving Data has a 6 seconds Cools down

Useful Links:

Data Stores

Did this article help?. If it did please Mark as answer.

0
This did not help in the slightest. All you did is explain what I said already it in different words (it freezes/throttles when exiting the game) The question is how do I stop that, not what it is because I already know what it is hattim00 80 — 2y
Log in to vote
0
Answered by 2 years ago

There are limits to datastores. Sometimes it needs to create a waiting list if it has to many requests, and so it will freeze the game. Try adding wait functions, removing or loosening your autosave function (if you have one), or try to save player's data when they leave, and remove those lines where you save data when the server closes.

0
I have tried that already which I already stated this is not a working solution. hattim00 80 — 2y
0
Ok. fiddyfiddler 18 — 2y
0
Maybe it won't be a problem, but is it saving data still, or is it failing? fiddyfiddler 18 — 2y

Answer this question