I am trying to make multiple leaderboards but i am getting this warning:

  1. What do i want to achieve?
    I want to make multiple leaderboards

  2. What is the issue?
    I am getting this warning:
    DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1159156951

Here is the code if needed:

local sg = script.Parent --Surface GUI
local sample = script:WaitForChild("Sample") --Our Sample frame
local sf = sg:WaitForChild("ScrollingFrame") --The scrolling frame
local ui = sf:WaitForChild("UI") --The UI list layout

local dataStoreService = game:GetService("DataStoreService")
--The data store service
local dataStore = dataStoreService:GetOrderedDataStore("Leaderboard")
--Get the data store with key "Leaderboard"
task.wait(3)
while true do
	for i,plr in pairs(game.Players:GetChildren()) do--Loop through players
		if plr.UserId>0 then--Prevent errors
			local ps = game:GetService("PointsService")--PointsService
			local w = plr.leaderstats.Rebirths.Value--Get point balance
			if w then
				pcall(function()
					--Wrap in a pcall so if Roblox is down, it won't error and break.
					dataStore:UpdateAsync(plr.UserId,function(oldVal)
						--Set new value
						return tonumber(w)
					end)
				end)
			end
		end
	end    
	
	function abbreviateNumber(n)
		local s = tostring(math.floor(n))
		return string.sub(s, 1, ((#s - 1) % 3) + 1) .. ({"", "K", "M", "B", "T", "QA", "QI", "SX", "SP", "OC", "NO", "DC", "UD", "DD", "TD", "QAD", "QID", "SXD", "SPD", "OCD", "NOD", "VG", "UVG"})[math.floor((#s - 1) / 3) + 1]
	end
	
	local smallestFirst = false--false = 2 before 1, true = 1 before 2
	local numberToShow = 100--Any number between 1-100, how many will be shown
	local minValue = 1--Any numbers lower than this will be excluded
	local maxValue = 10e30--(10^30), any numbers higher than this will be excluded
	local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
	--Get data
	local top = pages:GetCurrentPage()--Get the first page
	local data = {}--Store new data
	for a,b in ipairs(top) do--Loop through data
		local userid = b.key--User id
		local points = b.value--Points
		local username = "[Failed To Load]"--If it fails, we let them know
		local s,e = pcall(function()
			username = game.Players:GetNameFromUserIdAsync(userid)--Get username
		end)
		if not s then--Something went wrong
			warn("Error getting name for "..userid..". Error: "..e)
		end
		local image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
		--Make a image of them
		table.insert(data,{username,points,image})--Put new data in new table
	end
	ui.Parent = script
	sf:ClearAllChildren()--Remove old frames
	ui.Parent = sf
	for number,d in pairs(data) do--Loop through our new data
		local name = d[1]
		local val = d[2]
		local image = d[3]
		local color = Color3.new(1,1,1)--Default color
		if number == 1 then
			color = Color3.new(1,1,0)--1st place color
		elseif number == 2 then
			color = Color3.new(0.9,0.9,0.9)--2nd place color
		elseif number == 3 then
			color = Color3.fromRGB(166, 112, 0)--3rd place color
		end
		local new = sample:Clone()--Make a clone of the sample frame
		new.Name = name--Set name for better recognition and debugging
		new.LayoutOrder = number--UIListLayout uses this to sort in the correct order
		new.Image.Image = image--Set the image
		new.Image.Place.Text = number--Set the place
		new.Image.Place.TextColor3 = color--Set the place color (Gold = 1st)
		new.PName.Text = name--Set the username
		new.Value.Text = tostring(abbreviateNumber(val))--Set the amount of points
		new.Value.TextColor3 = color--Set the place color (Gold = 1st)
		new.PName.TextColor3 = color--Set the place color (Gold = 1st)
		new.Parent = sf--Parent to scrolling frame
	end
	task.wait()
	sf.CanvasSize = UDim2.new(0,0,0,ui.AbsoluteContentSize.Y)
	--Give enough room for the frames to sit in
	task.wait(180)
end

The codes are both the same but instead of oofs the other one is for Rebirths

Maybe you trying to update data too quick

That happens when you send too many requests.
Here you can see all limits for datastores. You can only get an ordered list 5 + numPlayers Ă— 2 times per minute.

You should move the datastore function calls outside of your while true do loop like 1NoFree said.

I also think that but how would i fix it?

so if i move this line: local ps = game:GetService(“PointsService”)–PointsService

outside this should fix it?

or this line?

dataStore:UpdateAsync(plr.UserId,function(oldVal)

The thing is that is updating the values every 0.03 Seconds. I suggest changing that time to 1-5 minutes as games do not usually autosave every 1 second to the server.

You can change that by changing:

while true do

To:

while wait(60) do

The line above will save the data to the datastore every 60 Seconds.

I would suggest using task.wait() instead of wait()

what is the differance

aaaaaaaaaaaaa

wait() is deprecated and task.wait() is the new better version of it.

ok thanks

fffffffffffffffffffff

i used what you said and after 60 seconds the same thing happend also the first 60 sec the leaderboard dident shown

There is not much difference between both but yeah. Also no wait is not deprecated. A lot of people use it.

i used it and the same thing happend but this time it took more for the leaderboard to load(60 sec)

What do you mean by it took more for the leaderboard to load? Isn’t it supposed to save after every 60 Seconds?

[EDIT] It’s not 60 Seconds because you have a wait(3) Before the while loop which begins with 63 seconds and autosaves after that, after that is just loops every 60 seconds.

When i tested it took 60 sec or more to load and after that i got the same error

Check if you have any other scripts containing SetAsync or UpdateAsync at the same way.

Besides the two leaderboards i have it in the leaderstats(SetAsync)

This is the code for the leaderstats:




local dataStoreService = game:GetService("DataStoreService")
local ds = dataStoreService:GetDataStore("DataStoreTest")

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

	local oofs = Instance.new("IntValue")
	oofs.Name = "OOFS"
	oofs.Parent = leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats

	local oofsData, rebirthsData
	local success, errormessage = pcall(function()
		oofsData = ds:GetAsync("oofs-"..plr.UserId)
		rebirthsData = ds:GetAsync("rebirths-"..plr.UserId)
	end)
	
	print("first works")
	
	if success then
		oofs.Value = oofsData
		rebirths.Value = rebirthsData
		print("second works")

	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormessage = pcall(function()
		ds:SetAsync("oofs-"..plr.UserId, plr.leaderstats.OOFS.Value)
		ds:SetAsync("rebirths-"..plr.UserId, plr.leaderstats.Rebirths.Value)
		
	
	end)
	print("final works")
end)

Any other script that saves and loads data?