-
What do you want to achieve? Fix my leaderboard script
-
What is the issue? My leaderboard is giving me this error below
-
What solutions have you tried so far? I tried to look at DevHub but i din’t found a solution.
Script:
local DataStoreService = game:GetService("DataStoreService")
local KillsLeaderBoard = DataStoreService:GetOrderedDataStore("KillsLeaderBoard")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = KillsLeaderBoard:GetSortedAsync(false,5)
local killPage = Data:GetCurrentPage()
for rank, data in ipairs(killPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local kills = data.Value
local IsOnLeaderboard = false
for i,v in pairs(game.Workspace.GlobalLeaderboard.LeaderboardGui.Holder:GetChildren()) do
if v.Player.Text == Name then
IsOnLeaderboard = true
break
end
end
if kills and IsOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Kills.Text = kills
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (0.8 * #game.Workspace.GlobalLeaderboard.LeaderboardGui.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGui.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetChildren()) do
KillsLeaderBoard:SetAsync(player.UserId, player.leaderstats.Kills.Value)
end
for _, frame in pairs(game.Workspace.GlobalLeaderboard.LeaderboardGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("updating")
wait(10)
end
Whats wrong on this script?