Need help with leaderboard script doesnt work

Hello iam Sam And iam trying to make an leaderboard

There some few errors there which cause the leaderboard doesnt work

as you can see in the output
they Printed the player.Timer.Second2.Value
BUT they Dont print the success that mean the code doesnt execute that line?
I guess error in some line between that 2 print

There no error output
If u found any error or things that not work i will really appriciate
Thanks alot

More info you can ask in comment

1 Like

I can’t speak for all of the issues you are having, but one immediate error that stands out is your excessive amount of DataStore requests. There are limits to DataStores, and one limit is that you cannot call too many within a certain time span.
Read the following article for more information. The subsection regarding DataStore limitations is toward the bottom of the page.

Could you provide more clarification on the other issues you’re dealing with?

I recently just started a print method to see which line of code doesnt work


and i saw this at line 17 the SavedData return nil so print cant found it
You know why ?

Can you send all of your code? We can’t really help with images

sure here it is

local TimerDataStore = DataStoreService:GetOrderedDataStore("TimerLeaderboard")

local leaderboardPart =  script.Parent.Parent.Parent
local RefreshRate = 5

local function RefreshLeaderboard()
	for i, player in pairs(game.Players:GetPlayers()) do 
		TimerDataStore:SetAsync(player.UserId, player.Timer.Second2.Value)
		print(player.Timer.Second2.Value)
	end
	local Success, Error = pcall(function()
		local Data = TimerDataStore:GetSortedAsync(false, 7)
		local TimerPage = Data:GetCurrentPage()
		for Rank, SavedData in ipairs(TimerPage) do
			local username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
			local Time = SavedData.Value
			
				print(SavedData.Value)
				local NewSample = game.ReplicatedStorage.Sample:Clone()
				NewSample.Visible = true
				NewSample.Parent = leaderboardPart.SurfaceGui.Frame
				NewSample.Name = username
				
				NewSample.Rank.Text = Rank
				NewSample.UserName.Text = username
				
				
				NewSample.Amount.Text =  Time
				print("Successs")
				
		end
	end)
end

while true do 
	for i, Frame in pairs(leaderboardPart.SurfaceGui.Frame:GetChildren()) do
		if Frame.Name ~=  "Sample" and Frame:IsA("Frame") then
			Frame:Destroy()
		end
	end
	RefreshLeaderboard()
	wait(RefreshRate)
end

Can you add a statement where it checks if the pcall failed to run or not? Maybe something like this

if not Success then
    print(Error)
end

Make sure to add it after the pcall function ends.


this ?

image
Add it after here.

it did print this

Workspace.leaderboard.Board.SurfaceGui.Frame.Script:29: invalid argument #3 (string expected, got nil)

This is line 29 of the script

local TimerDataStore = DataStoreService:GetOrderedDataStore("TimerLeaderboard")

local leaderboardPart =  script.Parent.Parent.Parent
local RefreshRate = 5

local function RefreshLeaderboard()
	for i, player in pairs(game.Players:GetPlayers()) do 
		TimerDataStore:SetAsync(player.UserId, player.Timer.Second2.Value)
		print(player.Timer.Second2.Value)
	end
	local Success, Error = pcall(function()
		local Data = TimerDataStore:GetSortedAsync(false, 7)
		local TimerPage = Data:GetCurrentPage()
		for Rank, SavedData in ipairs(TimerPage) do
			local username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
			local Time = SavedData

			print(SavedData)
			local NewSample = game.ReplicatedStorage.Sample:Clone()
			NewSample.Visible = true
			NewSample.Parent = leaderboardPart.SurfaceGui.Frame
			NewSample.Name = username

			NewSample.Rank.Text = Rank
			NewSample.UserName.Text = username


			NewSample.Amount.Text =  Time
			print("Successs")

		end
	end)
	if not Success then
		print(Error)
	end
end

while true do 
	for i, Frame in pairs(leaderboardPart.SurfaceGui.Frame:GetChildren()) do
		if Frame.Name ~=  "Sample" and Frame:IsA("Frame") then
			Frame:Destroy()
		end
	end
	RefreshLeaderboard()
	wait(RefreshRate)
end

Try running this.

i printed the saved data
it return the table.Name
which is a bunch of anonymous character lol

Does it work? Can you show the output?

Whoops Sorry for waste you all time
MY friend Fixed this for me
he said it must be SavedData.value and v must be lowercase since key is lowercase too
idk how it work but it really worked for my game xd

BTW THANKS YALL ALOT