DataStore request was added to queue. If request queue fills, further requests will be dropped warning

Ok so I have this script which works fine for the most part:


local Players = game:GetService('Players')
local TempPart = script.Parent
local SurfaceGui = TempPart.SurfaceGui
local MainFrame = SurfaceGui.Frame
local Template = script['Template']
local RecentlySaved = {}
local DataStoreService = game:GetService('DataStoreService')
local GlobalLeaderboardB = DataStoreService:GetOrderedDataStore(":GlobalWins")
if not game["Run Service"]:IsStudio() then
	GlobalLeaderboardB = DataStoreService:GetOrderedDataStore("Game:GlobalWins")
end

local CurrencyName = "Wins"
local ListSize = 100
local UpdateEvery = 10
local MinimumRequirement = 0

local _functions = {}

_functions.returncurrency = function(v)
	local x = 0
	local leaderstats = v:FindFirstChild("leaderstats")
	if leaderstats then
		local currency = leaderstats:FindFirstChild(CurrencyName)
		if currency and (currency:IsA("IntValue") or currency:IsA("NumberValue")) then
			x = currency.Value
		end
	end
	return x
end

_functions.removefromrecentlysaved = function(PlayerName)
	for i, v in pairs(RecentlySaved) do
		if v == PlayerName then
			table.remove(RecentlySaved, i)
			break
		end
	end
end

_functions.autoremoverecentsaved = function(PlayerName)
	spawn(function()
		wait(15)
		for i, v in pairs(RecentlySaved) do
			if v == PlayerName then
				table.remove(RecentlySaved, i)
				break
			end
		end
	end)
end

_functions.returnplayerlist = function()
	local int = 0
	for i, v in pairs(Players:GetPlayers()) do
		if _functions.returncurrency(v) > MinimumRequirement then
			int += 1
		end
	end
	return int
end

_functions.clear = function()
	for i, v in pairs(MainFrame:GetChildren()) do
		if v:IsA('Frame') then
			v:Destroy()
		end
	end
end

_functions.abbreviate = function(value, idp)
	if value < 1000 then
		return math.floor(value + 0.5)
	else
		local abbreviations = {"", "K", "M", "B", "T"}
		local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
		local abbrevs = abbreviations[1 + ex] or ("e+" .. ex)
		local normal = math.floor(value * ((10 ^ idp) / (1000 ^ ex))) / (10 ^ idp)
		return ("%." .. idp .. "f%s"):format(normal, abbrevs)
	end
end

local function updateLeaderboard()
	_functions.clear()
	local Pages = GlobalLeaderboardB:GetSortedAsync(false, ListSize)
	local TopList = Pages:GetCurrentPage()
	for Rank, SavedData in ipairs(TopList) do
		local UserId = SavedData.key
		local CAmount = SavedData.value
		if CAmount >= MinimumRequirement then
			local Template = script['Template']:Clone()
			Template.Parent = MainFrame
			Template.LayoutOrder = Rank
			Template.Score.Text = "" .. _functions.abbreviate(CAmount, 1)
			local function SetRankText(n)
				local A = {}
				A[1] = function()
					Template.Rank.Text = "🥇"
				end
				A[2] = function()
					Template.Rank.Text = "🥈"
				end
				A[3] = function()
					Template.Rank.Text = "🥉"
				end
				if n <= #A then
					A[n]()
				else
					Template.Rank.Text = "#" .. n
				end
			end
			SetRankText(Rank)

			local User = "Unknown"
			local Success, Errormsg = pcall(function()
				User = Players:GetNameFromUserIdAsync(UserId)
			end)
			if Success then
				pcall(function()
					Template.Username.Text = User
					Template.Name = User
				end)
			else
				warn(Errormsg)
			end
		end
	end
end

Players.PlayerAdded:Connect(function(Player)
	updateLeaderboard()
end)

Players.PlayerRemoving:Connect(function(Player)
	local PName = Player.Name
	if not table.find(RecentlySaved, Player.Name) then
		table.insert(RecentlySaved, Player.Name)
		local CurrentCurrencyAmount = _functions.returncurrency(Player)
		local Success, Errormsg = pcall(function()
			GlobalLeaderboardB:SetAsync(Player.UserId, CurrentCurrencyAmount)
		end)
		if not Success then warn(Errormsg) end
		_functions.removefromrecentlysaved(PName)
	end
end)

while true do
	for i, Player in pairs(Players:GetPlayers()) do
		local PName = Player.Name
		if not table.find(RecentlySaved, Player.Name) then
			table.insert(RecentlySaved, Player.Name)
			local CurrentCurrencyAmount = _functions.returncurrency(Player)
			local Success, Errormsg = pcall(function()
				GlobalLeaderboardB:SetAsync(Player.UserId, CurrentCurrencyAmount)
			end)
			if not Success then warn(Errormsg) end
			_functions.autoremoverecentsaved(PName)
		end
	end
	updateLeaderboard()
	task.wait(UpdateEvery)
end

Its purpose is to update a leaderboard every 10 seconds but after around like 10 minutes of just letting it run it starts printing

“DataStore request was added to queue. If request queue fills, further requests will be dropped”

and taking long to update and leaving the leaderboard that previously updates with new data instantly blank for long periods of time.

From what i gathered it’s because its updating and thus requesting DataStore too quickly, however why then does it work fine for the first 10 minutes or so before this error occurs and would setting the update interval to like a minute or something resolve the issue?

The time you are waiting is too short. Since there is a lot of player data in the game or just data for the DataStore to handle, it will start dropping requests to keep itself from overloading and crashing. So just increasing the wait time to about 5 minutes should fix it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.