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