What does "Request was throttled. Try sending fewer requests. Key = (...)" mean?

After I autosave players data, I get this warning: 21:43:10.947 - Request was throttled. Try sending fewer requests. Key = Key26266254

Anyone know what this means and why it might be happening?

1 Like

You’re hitting data store throttles.

http://robloxdev.com/articles/Data-store

Ctrl+F Limitations.

3 Likes

I’m only saving a simple number value every 60 seconds, I don’t see why I should be hitting limits.

Can we see your SetAsync/UpdateAsync function?

1 Like

I’ll provide most of the data script since it explains its self.

-- // Tom_atoes Datastore (22/07/18)

local DS = game:GetService("DataStoreService"):GetDataStore("Raig3")
local DataTable = {}
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Plr)
	local Key = "Key" .. Plr.UserId 
	local Data
	local Success, Error
	
	repeat
		
		Success, Error = pcall(function()
			Data = DS:GetAsync(Key)
		end)
		
		-- // Checks if data has loaded		
		
		if not Success then
			print("An error occured whilst trying to load " .. Plr.Name .. "'s data.")
			wait(1)
		else
			print(Plr.Name .. "'s data loaded successfully!")
		end
	
	-- // Loads data or makes new data	
		
	until Success or not Plr or not Plr.Parent
	
	if Plr and Plr.Parent then
		
		DataTable[Plr]	 = Data or {
			Cash = 50
		}	
		
	end
	
	-- // Autosaving	
	
	coroutine.resume(coroutine.create(function()
		while true do
			wait(60)
			if Plr and Plr.Parent and DataTable[Plr] then
				repeat
					
					Success, Error = pcall(function()
						Data = DS:SetAsync(Key, DataTable[Plr])
					end)
					
					if not Success then
						print("An error occured whilst trying to autosave " .. Plr.Name .. "'s data.")
						wait(6)
					else
						print(Plr.Name .. "'s data autosaved successfully!")
					end					
					
				until Success
				
			end
		end
	end))
end)

Players.PlayerRemoving:Connect(function(Plr)
	local Key = "Key" .. Plr.UserId
	local Success, Error
	
	Success, Error = pcall(function()
		DS:SetAsync(Key, DataTable[Plr])
	end)
end)

What’s your max player limit and how many players on average do you have in your server?

1 Like

Usually around 4 - 6 players and 10 player limit.

Are there any other data scripts in your game?

No there isn’t

Your issue is the section where you handle autosaving. You autosave individual player data every 60 seconds but in a loop starting at the moment a player joins. If another player joins 60 seconds later and another 60 seconds after that, that’s 3 players saving at pretty much the same time which could hit this limit and give you this warning.

Instead, handle autosaving outside of the playerAdded in a main loop that grabs all players in the game and spaces out the saving, like so:

-- Simple Autosave loop:
while true do
	-- Get current players playing:
	for i, player in pairs(game.Players:GetPlayers()) do
		wait(3) -- to not spam datastore for each player.
		-- Check if players are still in the game:
		if game.Players:FindFirstChild(tostring(player)) then
			saveData(player)
		end
	end
	wait(150) -- 3 minute cooldown.
end
10 Likes

I’m supposing that instead of saveData(player), I would move my Data variable outside of my player added function.Then I would change the script you sent me to this:

coroutine.resume(coroutine.create(function()
	while true do
		for i, Plr in pairs(game.Players:GetPlayers()) do
			local Key = "Key" .. Plr.UserId
			wait(3)
			if game.Players:FindFirstChild(tostring(Plr)) then
				Data:SetAsync(Key, DataTable[Plr])
			end
		end
		wait(150)
	end
end))

yes that would work too. Also no need to coroutine it if its the last loop in the script with nothing below it.

1 Like

Does this occur after every autosave, or only after a player leaves? There is a very big distinction there.

Also @Dev_Ryan, your solution doesn’t check if DataTable[Plr] exists. Should probably fix that, unless you want to wipe data.

A yes, I assumed he knew that so I was only providing tips on the autosave loop itself.

I’ve only noticed it after autosaves, not sure if it happens when a player leaves but I’ll test that now.

I’m new to using data store but I’m assuming that I’ll just edit

if game.Players:FindFirstChild(tostring(Plr)) then

to

if game.Players:FindFirstChild(tostring(Plr)) and DataTable[Plr] then
1 Like

This doesn’t make much sense. The rate limit is increased by the number of players in the game by 10 per minute per player. How could the cap be hit if the cap is directly being raised?

http://robloxdev.com/articles/Data-store

rate: 60 + 10*number of players

1 Like

While on this topic, when this warning comes up, does that mean the request will be sent again as soon as it can, or that the request failed and the developer should try again in a bit?

As far as I know, it’s the warning you get when it’s about to yield to wait until the throttle is over.

1 Like

Pretty much what I was going to say - additionally, at least from my experience, it’s better to save when an update occurs to the player’s data, rather than on an interval.