Datastore works fine until it seemingly randomly throws hundreds of warnings

recently I started experiencing a warning that has to do with datastores, and I am extremally confused by it. it seems to only happen when 2 or more people are in the game, but it does not start until a while after the second person joins.

  09:17:14.604  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:14.606  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:14.606  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:15.606  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:15.607  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:15.608  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:15.608  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:16.605  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:16.605  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:16.606  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:16.606  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:16.606  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:17.604  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:17.604  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:17.605  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:17.605  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:18.604  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:18.604  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio
  09:17:18.605  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -2  -  Studio
  09:17:18.605  DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = -1  -  Studio

my game runs fine for a few minutes, and then the output becomes filled with hundreds of the same warning.

here are the scripts that control my datastore.

Game.Players.PlayerAdded:Connect(function(Plr)
DataSuccessTable = {}
	
	local Success, ErrorMsg
	local Data
	repeat 
		Success, ErrorMsg = pcall(function()
			Data = HitStore:GetAsync(Plr.UserId..".Hits")
		end)
		print("D1")
	until Success or not Players:FindFirstChild(Plr)

	if Success then
		HitValue.Value = Data
		table.insert(DataSuccessTable, Plr.UserId)
	elseif not Success then
		print("datastore broken")
		warn(ErrorMsg)
		Plr:Kick("there was an error getting your save data. please rejoin, if this issue persists contact an admin.")
	end
end
game.Players.PlayerRemoving:Connect(function(Plr)
	
	local Success, ErrorMsg
	if table.find(DataSuccessTable, Plr.UserId) then
		repeat
			Success, ErrorMsg = pcall(function()
				print("D2")
				HitStore:UpdateAsync(Plr.UserId..".Hits", function(OldValue)
					if Plr.leaderstats["Hit's"].Value then
						return Plr.leaderstats["Hit's"].Value
					else
						return nil
					end
				end)
			end)
		until Success
		
		if Success then
			print("data saved")
		elseif not Success then
			print("Data not saved")
			warn(ErrorMsg)
		end
	end
end)

as you can see, in both of these I print something. I was using this for bugtesting to see if I could see what datastore the error is coming from. D1 prints at the start of the script, and then when the warnings come neither D1 or D2 is printed. I have used 0 free models, I am the only one working on the game, and I checked all of my plugins. from what I can tell the error does not effect anything and the data still saves, however it is just annoying to have it spammed, and a little off putting as I don’t want thousands of random datastore requests in my game. does anyone know what the heck is going on? thanks in advance!

That’s because there is a cooldown of 6 seconds for saving/updating the same key and if that fails it will make another request to write the value of the key. Take the function out of the repeat loop or add a task.wait(6) before the until statement

2 Likes

This is a little cleaner

local DataSuccessTable = {}
game:GetService("Players").PlayerAdded:Connect(function(Plr)
	local Success, Data = pcall(HitStore.GetAsync, HitStore, Plr.UserId..".Hits")
	if Success then
		warn("Datastore broken:", Data)
		Plr:Kick("there was an error getting your save data. please rejoin, if this issue persists contact an admin.")
	else
		HitValue.Value = Data
		table.insert(DataSuccessTable, Plr.UserId)
	end
end)
game:GetService("Players").PlayerRemoving:Connect(function(Plr)
	if not table.find(DataSuccessTable, Plr.UserId) then
		return
	end
	

	local Value = Plr.leaderstats["Hit's"].Value
	local Success, ErrorMsg = pcall(HitStore.SetAsync, HitStore, Plr.UserId..".Hits", Value, {Plr.UserId})
	if Success then
		print("data saved")
	else
		print("Data not saved")
		warn(ErrorMsg)
	end
end)

Why check again and again if it got the data if that will still kick the player?

weird thing is that D1/D2 stops printing, and only the warnings continue. Wouldn’t D1/D2 continue printing?

I didn’t even think about the fact that the player will get kicked. I added the kick after I was testing and the loop timed out and caused data loss, but your right, the loop is unneeded if it kicks you.

hey, I added a wait, and removed the loop on the GetAsync request. it still throws all the warnings, I am unsure why. anything else I can try?

First of all can you send the line where it is throwing the error?

it gives me no line, that is one of the reasons I am having such a hard time solving it. This is all it gives me.

Well then add a print where you have the warn statements. Also does that happen when you leave or when you join?

adding a print rn. it happens during neither. from what I can tell, it does not happen with a single player, only 2. it does not print for around 2-5 minutes, and then begins spamming. It seemingly happens at random, it starts to happen when nothing related to datastores is even happening.

edit: just added print’s into the warning’s, it still throws the same error, it does not print anything new. also, the key may be important. I have searched on the devforum a little, and no one else has negative keys.

edit 2: key is due to me being in testing mode I think, the testing accounts have - user id’s. this happens in public server’s though, just with normal user ID’s.

edit 3: I am testing in a normal server again, it seems to not be happening. I am super confused, I am gonna test more.

Well prints were meant to identify the section that was firing the warn. For example the first warn print(1), the second print(2) etc. But anyways that error happens when you save data so you may want to check that part of your code, also you may want to debug it a bit more. What I use to do it to add a print statement after each significant function/event to know where it stops running (breaks). As I told you before that error happens when you attempt to edit the same key’s value more than once in a too short period (6 seconds) because there is a cooldown between each request for key of 6 seconds and the error is probably happening because your UpdateAsync function is not successful and the repeat runs it again without a cooldown.

local Data, Success, ErrorMsg
local Attempts = 4
repeat
	Attempts -= 1
	Success, ErrorMsg = pcall(function()
		Data = HitStore:GetAsync(Player.UserId..".Hits")
	end)
	if not Success then wait(1) end
until
	Success or Attempts == 0 or not game.Players:GetPlayerByUserId(Player.UserId)
2 Likes

I have added a task.wait(6) to update async, it should no longer be the problem. I also have scattered multiple print(number of line print is on here), however all of them fire, because the script never actually stops, it just throws warnings. I also added warn(number of line here..ErrorMsg) to all the warnings, however none of the warnings come out with a line number, they all look like

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

Idk this gonna work or not but can you put this code. But i think the errors occurs because you are saving data too fast that the data store can’t handle it.

game:BindToClose(function()
      task.wait(3)
    end
1 Like