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

Getting DataStore Error "DataStore Request Added To Queue, further requests will be dropped"?

Asked by
Soban06 410 Moderation Voter
4 years ago

I have these 2 files (which I will show soon after explaining), called Leader board and Skips. The Leader board files simply creates a leader board and the skips script creates skips inside the player. I am using datastores on both of these scripts (leader board and skips).

I have recently implemented BindToClose() function in my Data Store.

Leaderboard Script:

01local DataStoreService = game:GetService("DataStoreService")
02local myDataStore = DataStoreService:GetDataStore("LeaderboardSavingSystem")
03 
04 
05game.Players.PlayerAdded:Connect(function(player)
06    local leaderstats = Instance.new("Folder", player)
07    leaderstats.Name = "leaderstats"
08 
09    local Checkpoint = Instance.new("IntValue", leaderstats)
10    Checkpoint.Name = "Stage"
11    Checkpoint.Value = 0
12 
13    local coins = Instance.new("IntValue", leaderstats)
14    coins.Name = "Coins"
15    coins.Value = 0
View all 92 lines...

And below is my Skips Script:

01local DataStoreService = game:GetService("DataStoreService")
02local DataStore = DataStoreService:GetDataStore("SkipsSavingSystem")
03 
04game.Players.PlayerAdded:Connect(function(player)
05    local SkipStages = Instance.new("Folder", player)
06    SkipStages.Name = "SkipStages"
07 
08    local Skips = Instance.new("IntValue", SkipStages)
09    Skips.Name = "Skips"
10    Skips.Value = 3
11 
12 
13    local data
14    local success, errormessage = pcall(function()
15        data = DataStore:GetAsync(player.UserId)
View all 56 lines...

So whenever I stop the game, I get the error "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key"

How can I remove this error so that the data is still going to get saved properly.

And can someone also explain me how to fix this issue because I may need to save more things other than these in the future. So if I can understand how to fix this than it will help a lot.

P.S: Can you check if I have implemented the BindToClose() function properly since I recently learnt it?

Thanks for any help

3 answers

Log in to vote
0
Answered by 4 years ago

That means any datastores your sending are being disregarded because your sending too many, you could get by that by making data save as a player leaves or manually save it though. And hey upvote this if you want im almost at 100 rep :)

0
So am I supposed to remove the BindToClose() function? Soban06 410 — 4y
0
no, check out my answer krowten024nabrU 463 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Try wrapping them in coroutines. Do it like this:

01game:BindToClose(function()
02    for _, player in ipairs(game.Players:GetPlayers()) do -- it doesn't really matter if it's pairs or ipairs
03        local data = {
04                Coins = player.leaderstats.Coins.Value;
05                Checkpoint = player.leaderstats.Stage.Value;
06                Rebirth = player.leaderstats.Rebirth.Value;
07            }
08        local success, err = pcall(function()
09            coroutine.wrap(function()
10                DataStore:UpdateAsync(player.UserId, function(oldTable) -- i don't know why i need so many `function()` things
11                    local newTable = oldTable
12                    newTable = data
13                    return newTable
14                end)
15            end)(player)
16        end)
17    end
18end)

^^ for your first saving script, vv

01game:BindToClose(function()
02    for _, player in ipairs(game.Players:GetPlayers()) do
03        local data = {
04                Skips = player.SkipStages.Skips.Value
05            }
06        local success, err = pcall(function()
07            coroutine.wrap(function()
08                DataStore:UpdateAsync(player.UserId, function(oldTable)
09                    local newTable = oldTable
10                    newTable = data
11                    return newTable
12                end)
13            end)(player)
14        end)
15    end
16end)

for saving skips. Hope this helps!

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

When BindToClose fires in Studio, PlayerRemoving also fires which results in data being in queue.

First thing, add this line in BindToClose :

1local RunService = game:GetService("RunService")
2 
3if RunService:IsStudio() then return end -- It will ensure that BindToClose won't fire while testing in studio

But, if you really want to test the saving in Studio:

01-- You MUST comment down the PlayerRemoving function (because when BindToClose fires, PlayerRemoving also fires[ONLY IN THE CASE OF STUDIO])
02--[[ game.Players.PlayerRemoving:Connect(function(plr)
03    coroutine.resume(coroutine.create(function()
04        DataSave(plr) -- Just an example function for saving
05    end))
06end)    ]]
07 
08game:BindToClose(function()
09    local RunService = game:GetService("RunService")
10 
11--  if RunService:IsStudio() then return end
12 
13    for _, plr in ipairs(game.Players:GetPlayers()) do -- Try using 'ipairs' as it is faster than 'pairs', but there's no 'i' in 'ipairs'. Use 'ipairs' in the case of arrays only.
14        coroutine.resume(coroutine.create(function()
15            DataSave(plr)
16        end))
17    end
18end)

Lemme know if it helps!

Answer this question