Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What script would I use to call for the player with the most kills on a leaderboard?

Asked by 9 years ago

I haven't really tried anything, I honestly wouldn't know where to start. If someone knows, it'd be greatly helpful :)

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Assuming the default leaderboard is used, we can assume that each Player's kills are stored in IntValues within an IntValue called 'leaderstats' within their Player object.

Basically, Players.adark.leaderstats.Kills.Value would get my kills.

To look at every player, we need to loop through them. We set a variable called topKills to record the player with the most kills, and check if the next player we find has more kills that them. At the end, we return that player with the most kills:

function getTopKills()
    local topKills

    for _, plr in ipairs(game.Players:GetPlayers()) do
        if not topKills or topKills.leaderstats.Kills.Value < plr.leaderstats.Kills.Value then
            topKills = plr
        end
    end

    return topKills
end
Ad

Answer this question