Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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

3 comments

0

@Jav, MAKE PEOPLE GIVE U REP!!!!! YOU GOTTA GET MORE BOI!!!! IM GIVIN ALL ON U!!!!

0

I just like answering scripting questions when I'm bored.

0

And also I meant like I have 3 values the biggest of the 1 of them qq

This discussion is preserved as it was. New answers, comments, and votes are closed.