Hello! For my game I made a script for a score
leaderboard. However, the score
local variable is always nil and I am unsure why, have I read the GetCurrentPage
wrong?
local DataStoreService = game:GetService("DataStoreService")
local OrderedPlayerScore = DataStoreService:GetOrderedDataStore("OrderedPlayerScore")
local PlayerDataFol = game.ReplicatedStorage.PlayerData
function FilterODSK(key)
return string.sub(key,2,#key)
end
function SyncLeaderB()
local Data = OrderedPlayerScore:GetSortedAsync(false,10,0,math.huge)
local CurPage = Data:GetCurrentPage()
for rank, inf in pairs(CurPage) do
local Username = game.Players:GetNameFromUserIdAsync(FilterODSK(inf.key))
local Score = inf.Value
local isOnLB = false
for i, v in pairs(game.Workspace.ScoreLB.LBgui.CoreFrame.BaseFrame:GetChildren()) do
if v.NameF.Text == Username then
isOnLB = true
break
end
end
if isOnLB == false and Score then
local NFrame = game.ServerStorage.Storage.GUI.PointFrame:Clone()
NFrame.Parent = game.Workspace.ScoreLB.LBgui.CoreFrame.BaseFrame
NFrame.Position = UDim2.fromScale(0,(0.9*rank))
NFrame.CountF.Text = Score
NFrame.NameF.Text = Username
elseif isOnLB == false and not Score then
warn("Score is missing")
end
end
end
function SaveScore()
local suc, err = pcall(function()
for _, v in pairs(PlayerDataFol:GetChildren()) do
local Score = v["Score"].Value
OrderedPlayerScore:SetAsync("s"..v.Name,Score)
end
end)
if suc then game.Workspace.ScoreLB.LBgui.CoreFrame.BaseFrame:ClearAllChildren() end
end
while true do
SaveScore()
local suc, err = pcall(SyncLeaderB)
if not suc then warn(err) end
task.wait(35)
end