Function giving an error

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    A donation leaderboard

  2. What is the issue?
    Keeps coming up with this error

  3. What solutions have you tried so far?
    Finding a solution

-- [ SETTINGS ] --

local StatsName = "R$ Donated" -- Your stats name
local MaxItems = 100 -- Max number of items to be displayed on the leaderboard
local MinValueDisplay = 1 -- Any numbers lower than this will be excluded
local MaxValueDisplay = 10e15 -- (10 ^ 15) Any numbers higher than this will be excluded
local UpdateEvery = 10 -- (in seconds) How often the leaderboard has to update

-- [ END SETTINGS ] --



local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
local SurfaceGui = script.Parent
local Sample = script.Sample
local List = SurfaceGui.Frame.List
local ItemsFrame = List.ListContent.Items

local function GetItems()
	local Data = DataStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
	local TopPage = Data:GetCurrentPage()
	
	ItemsFrame.Nothing.Visible = #TopPage == 0 and true or false
	
	for i, v in ipairs(TopPage) do
		local UserId = v.key
		local Value = v.value
		local Username = "[Not Available]"
		local Color = Color3.fromRGB(38, 50, 56)
		
		local Success, Error = pcall(function()
		 	Username = game.Players:GetNameFromUserIdAsync(UserId)
		end)
		
		if i == 1 then
			Color = Color3.fromRGB(255, 215, 0)
		elseif i == 2 then
			Color = Color3.fromRGB(192, 192, 192)
		elseif i == 3 then
			Color = Color3.fromRGB(205, 127, 50)
		end
		
		local Item = Sample:Clone()
		Item.Name = Username
		Item.LayoutOrder = i
		Item.Values.Number.TextColor3 = Color
		Item.Values.Number.Text = "#"..i
		Item.Values.Username.Text = Username
		Item.Values.Value.Text = Value
		Item.Parent = ItemsFrame
	end
end

while true do
	for i, v in pairs(game.Players:GetPlayers()) do
		local Stats = v:WaitForChild(StatsName).Value
		if Stats then
			pcall(function()
				DataStore:UpdateAsync(v.UserId, function(Value)
					return tonumber(Stats)
				end)
			end)
		end
	end
	
	for i, v in pairs(ItemsFrame:GetChildren()) do
		if v:IsA("ImageLabel") then
			v:Destroy()
		end
	end
	
	GetItems()
	
	wait()
	SurfaceGui.Heading.Text = StatsName .. " Leaderboard"
	List.ListContent.GuideTopBar.Value.Text = StatsName
	List.CanvasSize = UDim2.new(0, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)
	wait(UpdateEvery)
end

Make sure you’ve enabled API access in studio.

I know the screenshot shows it disabled, I grabbed it from Google.

Yes it is enabled api services

Hmm… It says in line 24 to 76 is the one causing the issue. Can you send a image of the error?

No, the error in the script. Click the main script, in the top of “Script Menu” is will show a button called “Go to Script Error” and also show the bottom error underneath the “Run a Command”

The issue isn’t with the script itself, it’s just that your are trying to access the datastore INCREDIBLY fast, you put the GetItems in a while loop, which causes to make a request every frame? That’s why they blocked your request so it cools down a bit, Don’t ever put Datastores in while loops that dont have a wait in them atleast

Read more about this article:

At the bottom there’s a section Limits.
There you can see what your wait(x) -- x is the amount of seconds should be, and how many request you can make per minutes.

Again please don’t put datastore request in fast loops as errors in scripts can occur, if you have to use it for the game’s sake, i recommend doing pcalls when requesting stuff, as if you get an error the script won’t stop working

It’s incredibly easy to understand

I’d suggest you use Roblox’s new MemoryStoreService, instead of DataStoreService.

You can read more about it here: