Data queue fills

Hello developers!

I have a issue with this leaderstats script for my obby game.
image
I get this error like 3 - 4 times. Any idea how i could fix this?

local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")

--// Variables \\--
local startTime = os.clock()
local loadTime = ReplicatedStorage:WaitForChild("loadTime")

local serverModulesFolder = ServerScriptService:WaitForChild("ServerModules")
local modules = ReplicatedStorage:WaitForChild("Modules")

local ConfigurationModule = modules:FindFirstChild("Configuration")
local Configuration = require(ConfigurationModule)

local dataStore2Module = serverModulesFolder:WaitForChild("DataStore2")
local dataStore2 = require(dataStore2Module)

local statsVersion = ReplicatedStorage:WaitForChild("gameVersion").Value 
local skipId = Configuration.ProductIds.skipId

local stageDataStore = DataStoreService:GetDataStore("StageData_"..statsVersion)
local deathsDataStore = DataStoreService:GetDataStore("DeathsData_"..statsVersion)
local coinsDataStore = DataStoreService:GetDataStore("CoinsData_"..statsVersion)

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = plr
	leaderstats.Name = "leaderstats"

	local stage = Instance.new("IntValue")
	stage.Parent = leaderstats
	stage.Name = "Stage"
	stage.Value = 1

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderstats

	local success, error = pcall(function()
		local data = stageDataStore:GetAsync(plr.UserId)
		if data then
			stage.Value = data.Stage or 1
			coins.Value = data.Coins or 0
		end
	end)

	if not success then
		warn("Error retrieving player data for "..plr.Name..": "..error)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, error = pcall(function()
		local data = {
			Stage = plr.leaderstats.Stage.Value,
			Coins = plr.leaderstats.Coins.Value
		}
		stageDataStore:SetAsync(plr.UserId, data)
	end)

	if not success then
		warn("Error saving player data for "..plr.Name..": "..error)
	end
end)

MarketplaceService.ProcessReceipt = function(info)
	local plr = game.Players:GetPlayerByUserId(info.PlayerId)
	if info.ProductId == skipId then
		plr.leaderstats.Stage.Value += 1
		plr:LoadCharacter()
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

local endTime = os.clock()
local elapsedTime = (endTime - startTime) * 75000

loadTime.Value = elapsedTime

There doesn’t seem to be anything that can cause the queue to fill up in this code, unless either the ConfigurationModule or the dataStore2Module or both are internally using DataStores in a way that would cause them to run when required

configurations is only this

local configuration = {
	--[[ Codes = {
		['RELEASE'] = {
			"Coins, 10" -- dont use currently
		};
	};
	]]--
	Admins = {
		1835750212;
	};
	Badges = {
		Welcome = 905312076573735;
	};
	ProductIds = {
		skipId = 1750102847,
	};
	Gamepasses = {
		doubleJump = 743963131,
		gravityCoil = 712182452,
		speedCoil = 807267339,
		greenBalloon = 807322273,
	};
	
}
return configuration

and datastore2 i don’t use so i removed the require

I’ll need to see the rest of the original code since the issue is happening somewhere below the code that’s provided

That’s all my code, there is nothing more

If that’s the case, then the issue is happening within a different script than the one provided

What could cause this? (30000)

That warning shows up if either one of a DataStore’s method is called in rapid succession (could either be GetAsync or SetAsync, most commonly SetAsync is being called too frequently within a loop when data attempts to save or when a server is shutting down)

isn’t it this part of the script

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormessage = pcall(function()
		stageDataStore:SetAsync(plr.UserId.. "-Stage", plr.leaderstats.Stage.Value)
		deathsDataStore:SetAsync(plr.UserId.. "-Deaths", plr.leaderstats.Deaths.Value)
		coinsDataStore:SetAsync(plr.UserId.. "-Coins", plr.leaderstats.Coins.Value)
	end)
end)

True, but the warning shouldn’t show up in this case since you’re using SetAsync on different DataStores, although you can try adding a task.wait between each statement as a test if you prefer

btw that code you provided isn’t part of the code you posted originally

1 Like

image
still like that

I’ll need to see the script where this code is written, please

1 Like
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")

--// Variables \\--
local startTime = os.clock()
local loadTime = ReplicatedStorage:WaitForChild("loadTime")

local modules = ReplicatedStorage:WaitForChild("Modules")

local ConfigurationModule = modules:FindFirstChild("Configuration")
local Configuration = require(ConfigurationModule)

local statsVersion = ReplicatedStorage:WaitForChild("gameVersion").Value 
local skipId = Configuration.ProductIds.skipId

local stageDataStore = DataStoreService:GetDataStore("StageData_"..statsVersion)
local deathsDataStore = DataStoreService:GetDataStore("DeathsData_"..statsVersion)
local coinsDataStore = DataStoreService:GetDataStore("CoinsData_"..statsVersion)

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = plr
	leaderstats.Name = "leaderstats"

	local stage = Instance.new("IntValue")
	stage.Parent = leaderstats
	stage.Name = "Stage"
	stage.Value = 1

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderstats

	local success, error = pcall(function()
		local data = stageDataStore:GetAsync(plr.UserId)
		if data then
			stage.Value = data.Stage or 1
			coins.Value = data.Coins or 0
		end
	end)

	if not success then
		warn("Error retrieving player data for "..plr.Name..": "..error)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, error = pcall(function()
		local data = {
			Stage = plr.leaderstats.Stage.Value,
			Coins = plr.leaderstats.Coins.Value
			-- Add other data you want to save
		}
		stageDataStore:SetAsync(plr.UserId, data)
	end)

	if not success then
		warn("Error saving player data for "..plr.Name..": "..error)
	end
end)

MarketplaceService.ProcessReceipt = function(info)
	local plr = game.Players:GetPlayerByUserId(info.PlayerId)
	if info.ProductId == skipId then
		plr.leaderstats.Stage.Value += 1
		plr:LoadCharacter()
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

local endTime = os.clock()
local elapsedTime = (endTime - startTime) * 75000

loadTime.Value = elapsedTime

This is quite an awkward situation, but this code:

isn’t written anywhere within this script:

You might need to use CtrlA to select the whole script’s text before copying the code

Yea, i saw that i’m so sorry i copied the wrong code in but this one is the right one:

local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")

--// Variables \\--
local startTime = os.clock()
local loadTime = ReplicatedStorage:WaitForChild("loadTime")

local modules = ReplicatedStorage:WaitForChild("Modules")

local ConfigurationModule = modules:FindFirstChild("Configuration")
local Configuration = require(ConfigurationModule)

local statsVersion = ReplicatedStorage:WaitForChild("gameVersion").Value 
local skipId = Configuration.ProductIds.skipId

local stageDataStore = DataStoreService:GetDataStore("StageData_"..statsVersion)
local deathsDataStore = DataStoreService:GetDataStore("DeathsData_"..statsVersion)
local coinsDataStore = DataStoreService:GetDataStore("CoinsData_"..statsVersion)

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = plr
	leaderstats.Name = "leaderstats"

	local stage = Instance.new("IntValue")
	stage.Parent = leaderstats
	stage.Name = "Stage"
	stage.Value = 1

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Value = 0
	coins.Parent = leaderstats

	local success, error = pcall(function()
		local data = stageDataStore:GetAsync(plr.UserId)
		if data then
			stage.Value = data.Stage or 1
			coins.Value = data.Coins or 0
		end
	end)

	if not success then
		warn("Error retrieving player data for "..plr.Name..": "..error)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, error = pcall(function()
		local data = {
			Stage = plr.leaderstats.Stage.Value,
			Coins = plr.leaderstats.Coins.Value
			-- Add other data you want to save
		}
		stageDataStore:SetAsync(plr.UserId, data)
	end)

	if not success then
		warn("Error saving player data for "..plr.Name..": "..error)
	end
end)

MarketplaceService.ProcessReceipt = function(info)
	local plr = game.Players:GetPlayerByUserId(info.PlayerId)
	if info.ProductId == skipId then
		plr.leaderstats.Stage.Value += 1
		plr:LoadCharacter()
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

local endTime = os.clock()
local elapsedTime = (endTime - startTime) * 75000

loadTime.Value = elapsedTime

Does the code work when testing in a separate place file?


@jayden752010 Did the warning also show up in a different place file? You didn’t reply to me, so I’m asking again just to make sure

I got that sometimes too with profile service I think you should wait with sending receust since it says that the queue is full the data store can only handle a certain amount of receusts in a time other it will be rejected that’s what I’ve learnt from @0Shank maybe he can explain more

What I think is that the script send to much receusts maybe it sent a receust each time the os date change

1 Like

That could actually be the issue let me try commenting it rq

edit: has no impact :confused:

A couple of things it could be.

  • You are making multiple DataStore requests at once, so further requests are being throttled until the other requests have been processed. Are you using a BindToClose so you don’t save the same data twice?
  • You have exceeded the request budget. All this means is after you exceed the budget, further requests are subject to throttling and will be added to the queue.

Remember, all this warning means is data needs a little more time to save, delay your requests a bit.

1 Like

Adding onto my previous post, you can use a BindToClose subprogram to make sure you are not spamming the store with duplicate requests.

local runService = game:GetService("RunService")
local players = game:GetService("Players")

game:BindToClose(function()
    if runService:IsStudio() or #players:GetPlayers() <= 1 then
        task.wait(3)
        return nil
    end

    for _, player in next, players:GetPlayers(), nil do
        --[[
            Save player data here. I would recommend
            converting your PlayerRemoving connection
            so it can be used not only to save data on leave
            but also to save data on game close.
        ]]
    end
    task.wait(3)
end)

you should also use UpdateAsync instead of SetAsync.