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

How do you get the highest number out of a leaderboard?

Asked by 10 years ago

So I tried to make a bunch of scripts for the past hour or so that would get the players that got the highest amount of coins but none worked. I wanted it 1-3rd most but all of my scripts failed. I think I made 13 attempts or so. Please help ASAP

1 answer

Log in to vote
1
Answered by
jav2612 180
10 years ago
players = game:GetService("Players")
highestValue = nil

for i, v in pairs(players:GetChildren()) do
    if v:FindFirstChild("leaderstats") ~= nil then
        for ii, vv in pairs(v.leaderstats:GetChildren()) do
            if highestValue == nil or vv.Value > highestValue then
                highestValue = vv.Value
            end
        end
    end
end

That should find the leaderstat with the highest's Value and give you that number

This I'm not 100% about, but it should give you the highest leaderstat instance and that stat's Value. It may take some experimenting if it doesn't work, but this is the general idea that I would use.

players = game:GetService("Players")
highestValue = nil
highestStat = {nil, 0]

for i, v in pairs(players:GetChildren()) do
    if v:FindFirstChild("leaderstats") ~= nil then
        for ii, vv in pairs(v.leaderstats:GetChildren()) do
            if highestValue == nil or vv.Value > highestValue then
                highestValue = vv.Value
                if highestValue > highestStat[2] or highestStat[1] == nil then
                    highestStat[1] = vv.Name
                    highestStat[2] = highestValue
                end
            end
        end
    end
end
0
@Jav, MAKE PEOPLE GIVE U REP!!!!! YOU GOTTA GET MORE BOI!!!! IM GIVIN ALL ON U!!!! RolandStudio 115 — 10y
0
I just like answering scripting questions when I'm bored. jav2612 180 — 10y
0
And also I meant like I have 3 values the biggest of the 1 of them qq RolandStudio 115 — 10y
Ad

Answer this question