Hey guy’s I am scripting a global leaderboard for my game but I ran into this error:
I can’t seem to see what the problem is
local DataStoreService = game:GetService("DataStoreService")
local GlobalLeaderboard = DataStoreService:GetOrderedDataStore("GlobalLeaderboard.1")
local RunService = game:GetService("RunService")
local leaderboard = {}
leaderboard.__index = leaderboard
function leaderboard:Refresh()
local Model = self.Model
local List = Model:FindFirstChild("Items",true)
local Time = os.time()
RunService.Heartbeat:Connect(function(deltaTime)
if os.time() - Time >= 5 then
Time = os.time()
for _, v in pairs(List:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
for _, player in pairs(game.Players:GetPlayers()) do
GlobalLeaderboard:SetAsync(player.UserId,player.leaderstats.Cash.Value)
end
--local success, err = pcall(function()
local data = GlobalLeaderboard:GetSortedAsync(false,10)--GetSortedAsync(false,10)
local page = data:GetCurrentPage()
for Rank,SavedData in pairs(page) do
local Username = game.Players:GetNameFromUserIdAsync(tonumber(SavedData.key))
local Cash = SavedData.value
local New = Instance.new("TextLabel")
New.Size = UDim2.new(1,0,.1,0)
New.Font = Enum.Font.SourceSansBold
New.TextScaled = true
New.Parent = List
New.Name = Username
New.Text = "#"..Rank.." "..Username.." "..Cash
New.Visible = true
end
--end)
--if not success then
-- warn(Model.." error:",err)
--end
end
end)
end
function leaderboard.new(Model)
local self = setmetatable({},leaderboard)
self.Model = Model
return self
end
return leaderboard