I created a cutscene with animations that plays at the end of round, i want to get player’s id which will be the number 1 in leaderboard at the end of round.
I literally dont have an idea how to do that, im bad with values, datas and etc. What methods do i use and when\where should i start?
Dummy that is in cutscene, has a script which grabs id of a player and copies his outfit, i need the id of leader on leaderboard when round ends
for i, v in pairs(workspace.Folder:GetChildren()) do
local number = v.Value
if number > highestnumber then
highestnumber = number
end
end
print(highestnumber)
local highestnumber = 0
for i, v in pairs(workspace.Folder:GetChildren()) do
local number = v.Value
if number > highestnumber then
highestnumber = number
end
end
print(highestnumber)
for i, child in ipairs(workspace.Folder:GetChildren()) do
if child.Value == highestnumber then
print(child)
end
end
just replace the folder:GetChildren() by the player’s kills or whatever you’re trying to meassure.
Then replace the second for loop getchildren by the players kills and there you go
table.sort is probably what you’re looking for. Here’s an example:
local Players = game:GetService("Players")
local function getTopPlayerExample()
local Values: {Player: Player, Score: NumberValue} = {}
for _, plr in pairs(Players:GetPlayers()) do
table.insert(Values, {
Player = plr,
Score= plr:WaitForChild("leaderstats").Points
})
end
table.sort(Values, function(a, b)
return a.Score.Value > b.Score.Value
end)
return Values[1].Player
end