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

i made a obby checkpoint script, and when I leave, I get this error, So I thought there was something wrong with setasync so I changed it to updateasync, which had the same error!!! anyways here is the code and the – lines are the setasync code


local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local ObbyDataStore = DataStoreService:GetDataStore("ObbyDataStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SkipStage = ReplicatedStorage:WaitForChild("SkipStage")
local ResetStage = ReplicatedStorage:WaitForChild("ResetStage")

local Checkpoints = workspace:WaitForChild("Checkpoints")
local inGameStartupPlayers = {}
local CurrentStage = {}
local TouchDb = {}

local ProductId = 1193721691

local SetCameraDirection: RemoteEvent = ReplicatedStorage.SetCameraDirection
local function NewCharacter(player: Player, char: Model)
	local TempCurrentStage = CurrentStage[player.UserId]
	local TempCheckpoint: BasePart = TempCurrentStage and Checkpoints:FindFirstChild(tostring(TempCurrentStage))
	if TempCheckpoint then
		task.wait()
		char:MoveTo(TempCheckpoint.Position)
		SetCameraDirection:FireClient(player, TempCheckpoint.Orientation)
	end
end

local function NewPlayer(player)
	local success, stage = pcall(function()
		return (ObbyDataStore:GetAsync(player.UserId)) or 1
	end)

	CurrentStage[player.UserId] = stage

	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local Stage = Instance.new("IntValue", leaderstats)
	Stage.Name = "Stage"
	Stage.Value = stage

	local TempChar = player.Character
	if TempChar ~= nil then
		NewCharacter(player, TempChar)
	end
	player.CharacterAdded:Connect(function(char)
		NewCharacter(player, char)
	end)
end

Players.PlayerAdded:Connect(function(player)
	if inGameStartupPlayers[player] == nil then
		NewPlayer(player)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	local success = pcall(function()
		--ObbyDataStore:SetAsync(player.UserId, CurrentStage[player.UserId])
		ObbyDataStore:UpdateAsync(player.UserId,function(oldValue)
			return CurrentStage[player.UserId] --your table over there
		end)
		--wait (6)
	end)
	CurrentStage[player.UserId] = nil
end)

SkipStage.OnServerInvoke = function(player)

	local connection
	local leaderstats = player:FindFirstChild("leaderstats")
	player.PlayerGui.Utilities.E.Modal = true
	if leaderstats ~= nil then
		local Stage = leaderstats:FindFirstChild("Stage")
		if Stage ~= nil then
			if #Checkpoints:GetChildren() ~= Stage.Value then
				local PurchaseResult = "Purchase Failed"
				connection = MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, purchased)
					player.PlayerGui.Utilities.E.Modal = false
					if player.UserId == userId and productId == ProductId then
						if purchased == true then
							PurchaseResult = "Success"
						
							player.PlayerGui.Utilities.E.Modal = false
						end
					end
					connection:Disconnect()
				end)
				MarketplaceService:PromptProductPurchase(player, ProductId)
				repeat wait(0.1) until connection.Connected == false or Players:GetPlayerByUserId(player.UserId) == nil
				return PurchaseResult
			else
				return "You have reached the highest stage!"
			end
		end
	end
end

ResetStage.OnServerEvent:Connect(function(player)
	CurrentStage[player.UserId] = 1
	local TempLeaderstats = player:FindFirstChild("leaderstats")
	if TempLeaderstats ~= nil then
		local TempStage = TempLeaderstats:FindFirstChild("Stage")
		if TempStage ~= nil then
			TempStage.Value = 1
		end
	end     
	NewCharacter(player, player.Character)
end)

MarketplaceService.ProcessReceipt = function(recieptInfo)
	if recieptInfo.ProductId == ProductId then
		local player = Players:GetPlayerByUserId(recieptInfo.PlayerId)
		if player ~= nil then
			CurrentStage[player.UserId] = CurrentStage[player.UserId] + 1
			local leaderstats = player:FindFirstChild("leaderstats")
			if leaderstats ~= nil then
				local Stage = leaderstats:FindFirstChild("Stage")
				if Stage ~= nil then
					Stage.Value = CurrentStage[player.UserId]
				end
			end
			local TempChar = player.Character
			if TempChar ~= nil then
				NewCharacter(player, TempChar)
			end
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

for i,v in pairs(Checkpoints:GetChildren()) do
	local StageNum = tonumber(v.Name)
	v.Touched:Connect(function(hit)
		local char = hit.Parent
		if char ~= nil then
			local Humanoid = char:FindFirstChildOfClass("Humanoid")
			if Humanoid ~= nil and Humanoid.Health > 0 then
				local player = Players:GetPlayerFromCharacter(char)
				if player ~= nil and (TouchDb[player.UserId] or 0) + 1 <= os.time() then
					TouchDb[player.UserId] = os.time()
					local TempCurrentStage = CurrentStage[player.UserId]
					if TempCurrentStage == StageNum - 1 then
						CurrentStage[player.UserId] = StageNum
						local TempLeaderstats = player:FindFirstChild("leaderstats")
						if TempLeaderstats ~= nil then
							local TempStage = TempLeaderstats:FindFirstChild("Stage")
							if TempStage ~= nil then
								TempStage.Value = StageNum
							end
						end
					end
				end
			end
		end
	end)
end

inGameStartupPlayers = Players:GetPlayers()
for i,v in pairs(inGameStartupPlayers) do
	spawn(function()
		NewPlayer(v)
	end)
end

game:BindToClose(function()
	for i,v in pairs(Players:GetPlayers()) do
		--ObbyDataStore:SetAsync(v.UserId, CurrentStage[v.UserId])
		ObbyDataStore:UpdateAsync(v.UserId,function(oldValue)
			return CurrentStage[v.UserId] --your table over there
		end)
		--wait(6)
	end
	wait(1)
end)

inGameStartupPlayers = {}
1 Like

The error message basically means that you’re updating the DataStore too frequently. Here’s a page on DataStore Errors and Limits.

huh, seems like they do the same thing…so there’s no fix?

Maybe it’s because when it hits the following code, it could spam the DataStore and cause the issue. Since you also call NewPlayer() when a player joins, maybe you can just remove this.

inGameStartupPlayers = Players:GetPlayers()
for i,v in pairs(inGameStartupPlayers) do
	spawn(function()
		NewPlayer(v)
	end)
end

Also, I don’t see where inGameStartupPlayers[player] is getting assigned after it’s cleared at the end of the script, so the following code will always be true and you can probably skip the if-check and just call NewPlayer(player):

Players.PlayerAdded:Connect(function(player)
	if inGameStartupPlayers[player] == nil then
		NewPlayer(player)
	end
end)

hmm I did both and the error is still there

I re-read your original post and see that it happens when you exit. So, I would say it’s probably in the BindToClose that’s flooding the datastore since it’s iterating over each player and calling UpdateAsync for each one. The commented out wait(6) is kind of long. Did you try it with something like wait(2) in the for-loop?

well i read a fourm post and the anwser was wait 6+ seconds so idk

You don’t need to worry unless it doesn’t save. This just means you are getting “ratelimited.”

hmmmm good idea im gonna do 8 players and see if it says for each and every one of them

1 Like