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

How do I fix this warning, I want to save the stats but I keep getting this warning:


I know it has to do with the loop but I need to get all the player in order to save the stats, how do I save the stats while not getting the warning message.

game:BindToClose(function()
	for i, plr in pairs(game:GetService("Players"):GetChildren()) do
		local rep = game:GetService("ReplicatedStorage")
		local plrStats = plr:FindFirstChild("Attributes")
		local weaponTable = {}
		local animationTable = {}
		
		for i, v in pairs(plrStats.Inventory.Weapons:GetChildren()) do
			if rep.Weapons:FindFirstChild(v.Name) then
				table.insert(weaponTable, v.Name)
			end
		end
		
		for i, v in pairs(plrStats.Inventory["Kill Animations"]:GetChildren()) do
			if rep.KillAnimations:FindFirstChild(v.Name) then
				table.insert(animationTable, v.Name)
			end
		end
		
		local suc, err = pcall(function()
			dataStore:SetAsync(plr.UserId.." Weapons", weaponTable)
			dataStore:SetAsync(plr.UserId.." Animations", animationTable)
			dataStore:SetAsync(plr.UserId.." Money", plrStats:FindFirstChild("Money").Value)
			dataStore:SetAsync(plr.UserId.." Current Weapon", plrStats:FindFirstChild("Current Weapon").Value)
		end)
	end
end)
2 Likes

You are sending too many save requests for it to handle. It puts the other ones it cannot handle in a queue and saves them when it has taken care of the others.

1 Like

The chances are that you probably also have a PlayerRemoving event which is connected to a function that also saves a player’s data. Do not worry, this warning message would not occur in a normal game. To rid this error from Studio, you can simply just use a conditional to check whether you’re on Studio in the PlayerRemoving function. Plug this conditional into the function connected to your PlayerRemoving event:

if not game:GetService("RunService"):IsStudio() then
    --Code to save data, here.
end
2 Likes

Is there a way to put dataStore:SetAsync outside the for loop while still getting the players Id?

Oh so it only send’s the warning when I’m running the script in the studio

Yes that is correct. This is due to the fact that both game:BindToClose() and PlayerRemoving are fired when you stop the test play in Studio.

1 Like

To minimize the amount of DataStore space you’re using, try saving all player data in a single table instead of having separate scopes for each section. For example, instead of doing this:

local plr = game:GetService("Players"):GetPlayers()[1] -- Example player for this demo
local plrStats = plr:WaitForChild("leaderstats")
local dataStore = game:GetService("DataStoreService"):GetDataStore("ExampleDataStore")


local weaponTable = {"AK47", "Sniper", "Shotgun"}
local animationTable = {"Hype", "Classic", "Renegade"}

local success, errorMessage = pcall(function()
    dataStore:SetAsync(plr.UserId.." Weapons", weaponTable)
    dataStore:SetAsync(plr.UserId.." Animations", animationTable)
    dataStore:SetAsync(plr.UserId.." Money", plrStats:FindFirstChild("Money").Value)
    dataStore:SetAsync(plr.UserId.." Current Weapon", plrStats:FindFirstChild("Current Weapon").Value)
end)
if not success then warn("Could not save data for " .. tostring(plr.Name) .. "!\nError: " .. errorMessage) end

You could pack all the values into a single table and then save it like so:

local playerData = {
    ["animations"] = animationTable;
    ["weapons"] = weaponTable;
    ["money"] = plrStats:FindFirstChild("Money").Value;
    ["currentWeapon"] =  plrStats:FindFirstChild("Current Weapon").Value
}

local success, errorMessage = pcall(function()
    dataStore:SetAsync(plr.UserId .. "_DATA", playerData)
end)
if not success then warn("Could not save data for " .. tostring(plr.Name) .. "!\nError: " .. errorMessage) end

You’d then be causing less stress on the server as well when getting the data by only calling GetAsync once:

local playerData
local success,errorMessage = pcall(function()
    playerData = dataStore:GetAsync(plr.UserId .. "_DATA")
end)

if success then
-- handle data
else
    plr:Kick("Error retrieving data\n" .. errorMessage .. "\nIf you continue to receive this error, please make a bug report")
end
5 Likes

Can putting it in one big table ever cause it to not save everything, if that save failed?

Does it queue it up, and keep trying?

Also why is the warning sporadic ? I have a datastore in a very small dev , with only 3 leaderstats being saved, and most of the time I do not see the warning, sometimes I do.

Is it also related to what everyone is doing datastores on Roblox causing bottlenecks on their side?

Thanks!

Actually currently I am saving every thing on a dictionary, so putting it to a dictionary won’t cause a failed, I think.

umm, I guess I’ll have to google dictionary…

what are the benefits to that verses datastore?

dictionary is a table like this:

local playerData = {
    animations = animationTable;
    weapons = weaponTable;
    money = plrStats:FindFirstChild("Money").Value;
    currentWeapon =  plrStats:FindFirstChild("Current Weapon").Value
}

As for the benefits I don’t know.

ahhh,
are you able to share the code that saves it and loads it?

although i guess there is more to it, that you are also building and adding to the tables during a players playing…

are you using code like what twinqle showed above?

1 Like

Well to save it you use the dataStore:SetAsync(plr.UserId.."-data", "The thing you wanna save, for me I used the dictionary since all the stuff that I wanna save is in that dictionary.") and to load it you use the dataStore:GetAsync(plr.UserId .. "-data")

Excellent verbiage!

Now if everyone documented their code as fantastic as you!
Thanks!
(I might be back for more questions… off to another topic, do you know 'Mesh, export to [what] from roblox studio, the easiest app/way to put / paint / do , customs texture? . I am going to start a post.

Hm, i woundt set playerData before hand because you know…
You can handle the data inside the pcall, and then if there’s an error then get default data.

1 Like