Leaderboard error

You can write your topic however you want, but you need to answer these questions:
I’m attempting to create a global leaderboard in game using the datastoreservice

my issue is “ServerScriptService.LeaderboardHandler:8: attempt to index nil with ‘GetCurrectPage’” which is causing the data to not save and the leaderboard to not display my time

ive tried tweaking the code but nothing has worked

ive pasted my script below

local DataStoreService = game:GetService("DataStoreService")
local timedatastore = DataStoreService:GetDataStore("TimeDataStore")
local leaderboard = game.Workspace.leaderboard.Model.GlobalLeaderboard

local function updateLeaderboard()
	local success, errorMessage = pcall(function()
		local Data = timedatastore:GetAsync(false, 5)
		local timePage = Data:GetCurrectPage()
		for Rank, Data in ipairs(timePage) do
			local username = game.Players:GetNameFromUserIdAsync(tonumber(Data.Key))
			local Name = username
			local Time = Data.Value
			local isOnLeaderboard = false
			for i, v in pairs(leaderboard.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end
			
			if Time and isOnLeaderboard == false then
				local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLbFrame.Player.Text = Name
				newLbFrame.Timeplayed.Text = Time
				newLbFrame.Rank.Text = "#"..Rank
				newLbFrame.Position = UDim2.new(0,0,newLbFrame.Position.Y.Scale + (0.08 * #leaderboard.LeaderboardGui.Holder:GetChildren()), 0)
				newLbFrame.Parent = leaderboard.LeaderboardGui.Holder
			end
		end
	end)
	
	if not success then
		print(errorMessage)
	end
end

while true do
	for _, Player in pairs(game.Players:GetPlayers()) do
		timedatastore:SetAsync(Player.UserId, Player.leaderstats.Time.Value)
	end
	
	for _, frame in pairs(leaderboard.LeaderboardGui.Holder:GetChildren()) do
		frame:Destroy()
	end
	
	updateLeaderboard()
	print("Updated Leaderboard")
	
	wait(10)
end
2 Likes

Couple issues,

  1. local Data = timedatastore:GetAsync(false,5)
    a. When you run GetAsync, the first argument has to be a string.
    GlobalDataStore | Documentation - Roblox Creator Hub

  2. local timePage = Data:GetCurrectPage()
    a. It is meant as GetCurrentPage. NOT ‘GetCurrectPage.’

Fix these errors accordingly and you’ll be back online.

// Edit //

With timedatastore:SetAsync, follow the [documentation] (GlobalDataStore | Documentation - Roblox Creator Hub).

Please read the documentation that’s given and learn from it. If you have persistent issues, please research it first.

I see where i messed up with the typo on the second issue, but can you please give me an example of what you mean in the first issue

For example,

here is one of mine.

DS:GetAsync(Player.UserId.."-ReservedServersv2")

I specifically link the players UserId so I can easily search for that player. Essentially, its a uniqueId.

i was going to do that but i cant find a way to grab the localplayer without putting the whole script in a playeradded function and i dont think that would work

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