Hey devs I really need help solving this piece of code here for the Globaleaderboard so I made 2 Values the Cash and Level…It shows on the part but the values are not updating they are just “1” I can’t seem to find the problem here and would appreciate it for guidance here’s the code
local DataStoreService = game:GetService('DataStoreService')
local LevelsLeaderboard = DataStoreService:GetOrderedDataStore("LevelsLeaderboard");
local CashLeaderboard = DataStoreService:GetOrderedDataStore("CashLeaderboard")
for _,player in pairs(game.Players:GetPlayers()) do
LevelsLeaderboard:SetAsync(player.UserId, player.leaderstats.Level.Value)
CashLeaderboard:SetAsync(player.UserId, player.leaderstats.EBits.Value)
end
local function updateLeaderboard()
local succes, errormessage = pcall(function()
local LevelData = LevelsLeaderboard:GetSortedAsync(false, 2)
local CashData = CashLeaderboard:GetSortedAsync(false, 2)
local LevelsPage = LevelData:GetCurrentPage()
local CashPage = CashData:GetCurrentPage()
for index, data in ipairs(LevelsPage, CashPage) do
local Username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = Username
local Level = data.value
local Cash = data.value
local isOnLeaderboard = false
for i,v in pairs(game.Workspace.GlobalLeaderboard.SurfaceGui.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
if Level and Cash and isOnLeaderboard == false then
local newLeaderboardFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLeaderboardFrame.Player.Text = Name
newLeaderboardFrame.Rank.Text = Level
newLeaderboardFrame.EBITS.Text = Cash
newLeaderboardFrame.Position = UDim2.new(0,0, newLeaderboardFrame.Position.Y.Scale + (.08*#game.Workspace.GlobalLeaderboard.SurfaceGui.Holder:GetChildren()),0)
newLeaderboardFrame.Parent = game.Workspace.GlobalLeaderboard.SurfaceGui.Holder
end
end
end)
if succes then
print("LEADERBOARD DATA HAS INNIT ")
else
print("ERROR IN LEADERBOARD DATA "..errormessage)
end
end --End of updateLeaderboard function
while true do
for _, frame in pairs(game.Workspace.GlobalLeaderboard.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("UPDATE LEADERBOARD! ")
wait(10)
end