Getting DataStore Error "DataStore Request Added To Queue, further requests will be dropped"?
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:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local myDataStore = DataStoreService:GetDataStore( "LeaderboardSavingSystem" ) |
05 | game.Players.PlayerAdded:Connect( function (player) |
06 | local leaderstats = Instance.new( "Folder" , player) |
07 | leaderstats.Name = "leaderstats" |
09 | local Checkpoint = Instance.new( "IntValue" , leaderstats) |
10 | Checkpoint.Name = "Stage" |
13 | local coins = Instance.new( "IntValue" , leaderstats) |
17 | local rebirth = Instance.new( "IntValue" , leaderstats) |
18 | rebirth.Name = "Rebirth" |
22 | player.CharacterAdded:Connect( function (character) |
24 | repeat wait() until player.character ~ = nil |
25 | local checkpoint = game.Workspace.Checkpoints:FindFirstChild(Checkpoint.Value) |
28 | character:WaitForChild( "HumanoidRootPart" ).CFrame = CFrame.new(checkpoint.Position + Vector 3. new( 0 , 2 , 0 )) |
38 | local success, errormessage = pcall ( function () |
40 | data = myDataStore:GetAsync(player.UserId) |
44 | if success and data then |
46 | coins.Value = data.Coins |
47 | Checkpoint.Value = data.Checkpoint |
48 | rebirth.Value = data.Rebirth |
57 | game.Players.PlayerRemoving:Connect( function (player) |
58 | local success, errormessage = pcall ( function () |
62 | Coins = player.leaderstats.Coins.Value; |
63 | Checkpoint = player.leaderstats.Stage.Value; |
64 | Rebirth = player.leaderstats.Rebirth.value; |
68 | myDataStore:SetAsync(player.UserId, data) |
75 | print ( "Data successfully saved!" ) |
77 | print ( "There was an error saving the data." ) |
82 | game:BindToClose( function () |
83 | print ( "BindToClose Function For Leaderboard Runs Now!" ) |
84 | for _, player in pairs (game.Players:GetPlayers()) do |
86 | Coins = player.leaderstats.Coins.Value; |
87 | Checkpoint = player.leaderstats.Stage.Value; |
88 | Rebirth = player.leaderstats.Rebirth.value; |
90 | myDataStore:SetAsync(player.UserId, data) |
And below is my Skips Script:
01 | local DataStoreService = game:GetService( "DataStoreService" ) |
02 | local DataStore = DataStoreService:GetDataStore( "SkipsSavingSystem" ) |
04 | game.Players.PlayerAdded:Connect( function (player) |
05 | local SkipStages = Instance.new( "Folder" , player) |
06 | SkipStages.Name = "SkipStages" |
08 | local Skips = Instance.new( "IntValue" , SkipStages) |
14 | local success, errormessage = pcall ( function () |
15 | data = DataStore:GetAsync(player.UserId) |
18 | if success and data then |
19 | Skips.Value = data.Skips |
21 | print ( "Error while fetching data!" ) |
29 | game.Players.PlayerRemoving:Connect( function (player) |
30 | local success, errormessage = pcall ( function () |
32 | Skips = player.SkipStages.Skips.Value |
35 | DataStore:SetAsync(player.UserId, data) |
39 | print ( "Skips Successfully Saved!" ) |
41 | print ( "There was an error while saving Skips!" ) |
48 | game:BindToClose( function () |
49 | print ( "BindToClose Function For Skips Runs Now!" ) |
50 | for _, player in pairs (game.Players:GetPlayers()) do |
52 | Skips = player.SkipStages.Skips.Value |
54 | DataStore:SetAsync(player.UserId, data) |
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