Global Leaderboard not working

Hello, I’m trying to make a global leaderboard for my game but when it tries to load the data, it gives me an error that I can’t get data because it was in a que. Here is the Error:

Datastore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.key = 2683401811 

Here is the code i’m using:

local DataStoreService = game:GetService("DataStoreService")
local DLeaderBoard = DataStoreService:GetOrderedDataStore("MostDonated")

local function updateDLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = DLeaderBoard:GetSortedAsync(false,5)
		local DPage = Data:GetCurrentPage()
		for Rank, data in pairs(DPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Donated = data.Value
			local isOnLeaderboard = false
			for i,v in pairs(game.Workspace.Map.TopDonators.Leaderboard.SurfaceGui.Leaderboard:GetChildren()) do
				
				
				if v.Name == Name then
					isOnLeaderboard = true
					break
				end
			end
			if Donated and isOnLeaderboard == false then
				local newLbFrame = game.Workspace.Map.TopDonators.Leaderboard.SurfaceGui.Leaderboard.Template:Clone()
				newLbFrame.Info.Username.Text = Name
				newLbFrame.Stats.Robux.Text = Donated
				newLbFrame.Info.Rank.Text = "#"..Rank
				newLbFrame.Position = UDim2.new(0,0, newLbFrame.Parent.Y.Scale + (.08 * #game.Workspace.Map.TopDonators.Leaderboard.SurfaceGui.Leaderboard:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.Map.TopDonators.Leaderboard.SurfaceGui.Leaderboard
				newLbFrame.Name = Name
			end
		end
	end)
	if not success then
		warn(errorMessage)
		warn("Data Store Failed to load... #Error 3030")
	end
end
while true do 
	for _,player in pairs(game.Players:GetPlayers()) do
		local currency = player.leaderstats.Donated.Value
		DLeaderBoard:SetAsync(player.UserId, currency)
		
	end
	for _,frame in pairs(game.Workspace.Map.TopDonators.Leaderboard.SurfaceGui.Leaderboard:GetChildren()) do
		frame:Destroy()
	end
	updateDLeaderboard()
	wait(5)
end

It’s because you’re setting data too quickly, try changing the wait(5) to task.wait(60) or more.

--//Services
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

--//Variables
local DLeaderBoard = DataStoreService:GetOrderedDataStore("MostDonated")
local Leaderboard = workspace.Map.TopDonators.Leaderboard.SurfaceGui.Leaderboard

--//Functions
local function updateDLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = DLeaderBoard:GetSortedAsync(false, 5)
		local DPage = Data:GetCurrentPage()
		
		for Rank, data in pairs(DPage) do
			local userName = Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Donated = data.Value
			local isOnLeaderboard = false
			
			for i, child in ipairs(Leaderboard:GetChildren()) do
				if child.Name == Name then
					isOnLeaderboard = true
					
					break
				end
			end
			
			if Donated and not isOnLeaderboard then
				local newLbFrame = Leaderboard.Template:Clone()
                newLbFrame.Name = Name
				newLbFrame.Info.Username.Text = Name
				newLbFrame.Stats.Robux.Text = Donated
				newLbFrame.Info.Rank.Text = "#"..Rank
				newLbFrame.Position = UDim2.new(0,0, newLbFrame.Parent.Y.Scale + (.08 * #Leaderboard:GetChildren()), 0)
				newLbFrame.Parent = Leaderboard
			end
		end
	end)
	
	if not success then
		warn(errorMessage)
		warn("Data Store Failed to load... #Error 3030")
	end
end

while task.wait(60) do 
	for _, player in ipairs(Players:GetPlayers()) do
		local currency = player.leaderstats.Donated.Value
		DLeaderBoard:SetAsync(player.UserId, currency)
		
		task.wait(1)
	end
	
	for _,frame in pairs(Leaderboard:GetChildren()) do
		frame:Destroy()
	end
	
	updateDLeaderboard()
end

After the 60 seconds it still adds it to a que

You’re making way too many requests here, and in my opinion you’re just going about it the wrong way entirely. Instead of constantly saving the player’s data, maybe save it once every 15 minutes. To ensure it’s saved when they leave, you can use the PlayerRemoving event, in combination with a separate folder that updates.

local P = game:GetService("Players")

P.PlayerAdded:Connect(function(player)
  local storage = Instance.new("IntValue",game:GetService("ServerStorage").playerData) -- Folder

  player.leaderstats.Donations.Changed:Connect(function(val)
    storage.Value = val
  end)

  while task.wait(900) do
    -- Update datastore
  end

end)

P.PlayerRemoving:Connect(function(player)
  local storage = game:GetService("ServerStorage").playerData:FindFirstChild(player.Name).Value
  -- Update DataStore with the storage value.
end)