How can I stop getting Data Store warnings on my Data store script?

Hi, I keep getting this warning when trying to save the player’s data: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 351006856

I have no idea what this means or what to do? Could I please have some help on how to fix this?

Code
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("MyDataStore") -- This can be changed to whatever you want

local function saveData(player) -- The functions that saves data
	

		local tableToSave = {
			Levels = player.leaderstats.Levels.Value; -- First value from the table
			Exp = player.leaderstats.Exp.Value;
		 -- Second value from the table
	}
	
	local success, err = pcall(function()
		dataStore:SetAsync(player.UserId, tableToSave) -- Save the data with the player UserId, and the table we wanna save
	end)
	
	if success then -- If the data has been saved
		print("Data has been saved!")
	else -- Else if the save failed
		print("Data hasn't been saved!")
		warn(err)		
	end
end


game.Players.PlayerAdded:Connect(function(player) -- When a player joins the game
	
	-- // Assigning player stats //
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local Levels = Instance.new("IntValue")
	Levels.Name = "Levels"
	Levels.Parent = leaderstats
	
	local Exp = Instance.new("IntValue")
	Exp.Name = "Exp"
	Exp.Parent = leaderstats 
	
	local OB = Instance.new("IntValue")
	OB.Name = "OB"
	OB.Parent = leaderstats

	local CB = Instance.new("IntValue")
	CB.Name = "CB"
	CB.Parent = leaderstats 
	
	
	
	local data -- We will define the data here so we can use it later, this data is the table we saved
	local success, err = pcall(function()
		
		data = dataStore:GetAsync(player.UserId) -- Get the data from the datastore
		
	end)
	
	if success then -- If there were no errors and player loaded the data
		Levels.Value = data["Levels"]
		Exp.Value = data["Exp"] -- Set the money to the first value of the table (data)
		-- Set the coins to the second value of the table (data)
		
	else -- The player didn't load in the data, and probably is a new player
		print("The player has no data!") -- The default will be set to 0
	end
	
end)

game.Players.PlayerRemoving:Connect(function(player) -- When a player leaves
	local success, err  = pcall(function()
		saveData(player) -- Save the data
	end)
	
	if success then
		print("Data has been saved")
	else
		print("Data has not been saved!")
	end
end)

game:BindToClose(function() -- When the server shuts down
	for _, player in pairs(game.Players:GetPlayers()) do -- Loop through all the players
		local success, err  = pcall(function()
			saveData(player) -- Save the data
		end)
		
		if success then
		else
		end
	end
end)

Thank you for your help!

Don’t send requests so quickly.

What do you mean by that? How should I fix it?

on a game:BindToClose(function()
dont loop all the players because you are using a datastore on everyone!

2 Likes

The warning is pretty much what it says, somewhere in your script your sending too many requests too soon. Look for places where this might be happening and maybe add a wait() to delay it.

1 Like

Oh, How would I not loop that function?(sorry I’m not the best scripter)

just use only a specific player!

everyone will get a bind on everytime they join

1 Like

Try to wait in the loop.

game:BindToClose(function()
	for _, player in pairs(game.Players:GetPlayers()) do
		local success, err  = pcall(function()
			saveData(player)
		end)
		
		if success then
		else
		end
        game:GetService("RunService").Heartbeat:Wait()
	end
end)
1 Like

No, It didn’t work I still got the warning

Here’s my solution from another post. Hope this helps

1 Like

I got a same as you but i already fix it

game:BindToClose(function()
wait(2)
end)

and it work perfectly

1 Like

Thanks, I will see if it works tomorrow!

The wait is not the issue.
The warning appears when you send too many requests with the same KEY
This is because it is trying to save data BOTH when the player leaves AND when the game closes

1 Like

How would I be able to fix the script in order to deceess the requests with the same key?

try not to use data store too much!

1 Like

That work! Thank you for your time.