I have this script for a leaderboard but it shows the highest amount of deaths. How do I make it so it shows the lowest amount of deaths at number 1.
local function updateLeaderboard2()
local success, errorMessage = pcall (function()
local Data =WinsLeaderboard2: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 Deaths = data.value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
if v.Name2.Text == Name then
isOnLeaderboard = true
break
end
end
if Deaths and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Name2.Text = Name
newLbFrame.TimeSpent.Text = Deaths
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
Yes and no, I did what you said but my values were all messed up. My deaths were 57 but it said 17 on the leaderboard. The sorting bit worked though.
local success, errorMessage = pcall (function()
local Data =WinsLeaderboard2:GetSortedAsync(true, 5)
local WinsPage = Data:GetCurrentPage()
for Rank, data in ipairs(WinsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Deaths = data.value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
if v.Name2.Text == Name then
isOnLeaderboard = true
break
end
end
if Deaths and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Name2.Text = Name
newLbFrame.TimeSpent.Text = Deaths
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
local Avg = math.floor(player.leaderstats["Avg Deaths"].Value + 0.5)
WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Seconds.Value,player.UserId, player.leaderstats.Deaths.Value,player.UserId, Avg)
end
for _, frame in pairs (game.Workspace.Locations.Leaderboardarea.LeaderboardArea.Leaderboard.LeaderboardGUI.Holder:GetChildren(),game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren(),game.Workspace.Locations.Leaderboardarea.LeaderboardArea3.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
updateLeaderboard1()
updateLeaderboard2()
g = g+1
print("Updated Seconds Leaderboard!",g)
print("Updated Deaths Leaderboard!",g)
print("Updated Avg Deaths Leaderboard!",g)
wait(60)
end