I’ve made a Global Leaderboard but if it updates nothing shows on it so i wanted to ask if anybody could help me since there was another topic but the person sound the solution by its self so im asking here again! would be nice if i could get a quick response
here my code:
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Wins = data.Value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
if Wins and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Wins.Text = Wins
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
end
for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end
it would be nice if you could send the fixed code when you may help me
Are there any errors? Are you testing in studio or roblox client? If you are on studio you have to turn on API services. Also, can you print out Rank and data in your loop? You also have to use pairs instead of ipairs.
Alr, surely take your time. My best guess is to remove that variable because from looking at the way this variable is used, I’m assuming that it’s just for checking if player is in leaderboards or not, but you don’t really need to check it.
Edit -
Hmm, then just remove the condition and this variable. I will send the code in a moment like how am I saying
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
print(Rank, data) --he means to add this line
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Wins = data.Value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
if Wins and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Wins.Text = Wins
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
end
for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Wins = data.Value
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Wins.Text = Wins
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
end
for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end
```local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = WinsLeaderboard:GetSortedAsync(false, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Wins = data.Value
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameWins"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Wins.Text = tostring(Wins)
newLbFrame.Rank.Text = "#"..tostring(Rank)
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 + #game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.userId, player.leaderstats.Wins.Value)
end
for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Wins.WinLeaderboard.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end
@Moneypro456789 thank you but ive not got it fixed but i need help at another globale leaderboard because there is nothing showing up AGAIN. this time the lobal leaderboard is a global death leaderboard
here is the code:
local DataStoreService = game:GetService("DataStoreService")
local DeathsLeaderboard = DataStoreService:GetOrderedDataStore("DeathsLeaderboard")
local function updateLeaderboard()
local success, errorMessage = pcall(function()
local Data = DeathsLeaderboard:GetSortedAsync(false, 5)
local DeathsPage = Data:GetCurrentPage()
for Rank, data in ipairs(DeathsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Deaths = data.value
local isOnLB = false
for i, v in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLB = true
break
end
end
if Deaths and isOnLB == false then
local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrameDeaths"):Clone()
newLBFrame.Player.Text = Name
newLBFrame.Deaths.Text = Deaths
newLBFrame.Rank.Text = "#"..Name
newLBFrame.Position = UDim2.new(0, 0, newLBFrame.Position.Y.Scale + (.1 * game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()), 0)
newLBFrame.Parent = game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
DeathsLeaderboard:SetAsync(player.UserId, player.leaderstats.Deaths.Value)
end
for _, frame in pairs(game.Workspace.Lobby.Leaderboards.Leaderboard_Deaths.DeathLeaderboard.SurfaceGui.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end
if i made any mistakes tell me or fix them if possible