this is different from my other topic.
Right now i am trying to get the death leaderstat of the players on the leaderboard, but its kind of hard! my brain cant think of a solution!
Script:
local DataStoreService = game:GetService("DataStoreService")
local KillsLeaderboard = DataStoreService:GetOrderedDataStore("KillsData")
local DeathLeaderboard = DataStoreService:GetOrderedDataStore("DeathsData")
local Players = game:GetService("Players")
local Leaderboard = workspace.LeaderboardFolder.Leaderboard
local Frame = Leaderboard.LeaderboardPart.LeaderboardGui.Holder
local LeaderboardFrame = game.ReplicatedStorage:WaitForChild("LeaderboardList")
local function UpdateLeaderboard()
local Success,ErrorMessage = pcall(function()
local KillsData = KillsLeaderboard:GetSortedAsync(false, 25)
local DeathsData = DeathLeaderboard:GetSortedAsync(false, math.huge) -- ???? (bit i am stuck on right now!)
local Page = KillsData:GetCurrentPage()
local DeathsPage = DeathsData:GetCurrentPage()
for Rank, data in ipairs(Page) do
print(data.key)
local Username = Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = Username
local Kills = data.value
local IsOnLeaderboard = false
for i,v in pairs(Frame:GetChildren()) do
if v:IsA("Frame") and v.Player.Name == Name then
IsOnLeaderboard = true
break
end
end
if Kills and IsOnLeaderboard == false then
local NewFrame = LeaderboardFrame:Clone()
NewFrame.Player.Text = Name
NewFrame.Kills.Text = Kills
NewFrame.Rank.Text = "#"..Rank
NewFrame.Rank.Place.Disabled = false
NewFrame.Parent = Frame
for _,DeathData in ipairs(DeathsPage) do
if DeathData.key == data.key then
NewFrame.Deaths.Text = DeathData.value
else
NewFrame.Deaths.Text = "nil"
end
end
end
end
end)
if not Success then
warn(ErrorMessage)
end
end
Obviously getting the sorted async with math.huge
is going to make an error, but replacing it with a reasonable number (like 100) would actually make this script work! but since there are obviously more people who have more deaths than me it wouldn’t show up on the list, since it gets the most deaths that a player has gotten!