DataStore "If request queue fills, further requests will be dropped" Output

This is a script for saving data to display on a donation board.
It works, but it’s firing too many data requests. I tried using waits but it didn’t seem to solve it, maybe I put them in the wrong place. The script was pre-written, I haven’t used datastore too much personally, hopefully someone can point me in the right direction thanks

local market=game:GetService("MarketplaceService")
local data=game:GetService("DataStoreService"):GetDataStore("Donations")
local ordered=game:GetService("DataStoreService"):GetOrderedDataStore("Donation")
local week=60*60*24*7
local weekno=math.floor(os.time()/week)

function saveordered()
	for i,v in pairs(game.Players:GetPlayers()) do
		ordered:SetAsync(v.UserId,v.Donations.Value)
	end
end

function weeklysave()
	local week=60*60*24*7
	local weekno=math.floor(os.time()/week)
	local weekly=game:GetService("DataStoreService"):GetOrderedDataStore(tostring(weekno))
	for i,v in pairs(game.Players:GetPlayers()) do
		weekly:SetAsync(v.UserId,v.Donations.Value)
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	local donations=Instance.new("IntValue",plr)
	donations.Name="Donations"
	donations.Value=0
	local success,value=pcall(function()
		return data:GetAsync(plr.UserId)
	end)
	if success then
		donations.Value=value
	end


	spawn(function()
		while wait(30) do
			for i,v in pairs(game.Players:GetPlayers()) do
				data:SetAsync(v.UserId,v.Donations.Value)
			end	
		end
	end)
end)


game.Players.PlayerRemoving:Connect(function(plr)
	data:SetAsync(plr.UserId,plr.Donations.Value)
	saveordered()
	weeklysave()
end)

game:BindToClose(function()
	for i,v in pairs(game.Players:GetPlayers()) do
		data:SetAsync(v.UserId,v.Donations.Value)
		saveordered()
		weeklysave()
	end
end)


function market.ProcessReceipt(receipt)
	-- receipt stuff
end

spawn(function()
	while wait(33) do
		saveordered()
		weeklysave()
	end
end)

Outputs:

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Data Store = Donation

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Data Store = xxxx

Please add a delay when you request and send data to the data store.

Make the delay for each save longer. This will stop the request queue from fully being filled up.

Thanks, i tried increasing the current waits to 300, and added waits in the for loops but still get the warning for some reason. do you know what part of the code this should be? i might be doing it wrong

I believe it’s because you’re still sending a lot of requests in a short time period. Try making the waits for each data saving different.

Your system right now just waits 300 seconds, and then rapidly saves data, and then waits another 300 seconds. That rapid saving of data probably causes it.

This is causing it to save all players for every player that comes in the game so say me and you go in the game it doesn’t just save my data every 30 seconds it is saving mine and yours 2 times every 30 seconds and this connection is never ending so more player the more connections which is why your are getting timeouts and a few other sets your are doing that are not necessary

you could remove the while loop here or better would be to move that while loop outside of the player added function just in the main script

Also you should only save a players data if it has changed

Also both of these should just call that 1 save function

1 Like

Original code was from a free model tutorial
i’ve updated it, some code was unnecessary it now works (i also had more than one donation board with duplicate scripts, i deleted the extras).

local market=game:GetService("MarketplaceService")
local data=game:GetService("DataStoreService"):GetDataStore("Donations")
local ordered=game:GetService("DataStoreService"):GetOrderedDataStore("Donation")

local week=60*60*24*7
local weekno=math.floor(os.time()/week)
local weekly=game:GetService("DataStoreService"):GetOrderedDataStore(tostring(weekno))

game.Players.PlayerAdded:Connect(function(plr)
	local donations=Instance.new("IntValue",plr)
	donations.Name="Donations"
	donations.Value=0
	local success,value=pcall(function()
		return data:GetAsync(plr.UserId)
	end)
	if success then
		donations.Value=value
	end
end)


game.Players.PlayerRemoving:Connect(function(plr)
	data:SetAsync(plr.UserId,plr.Donations.Value) 
	wait()
	ordered:SetAsync(plr.UserId,plr.Donations.Value)
	wait()
	weekly:SetAsync(plr.UserId,plr.Donations.Value)
end)

game:BindToClose(function()
	for i,v in pairs(game.Players:GetPlayers()) do
		data:SetAsync(v.UserId,v.Donations.Value)
		ordered:SetAsync(v.UserId,v.Donations.Value)
		weekly:SetAsync(v.UserId,v.Donations.Value)
		wait(6)
	end
end)


function market.ProcessReceipt(receipt)
	-- receipt stuff
end

spawn(function()
	while wait(30) do
		for i,v in pairs(game.Players:GetPlayers()) do
			weekly:SetAsync(v.UserId,v.Donations.Value)
			ordered:SetAsync(v.UserId,v.Donations.Value)
			data:SetAsync(v.UserId,v.Donations.Value)
			wait(6)
		end	
	end
end)

thanks everyone for the help!!