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

i need to get the highest value(highscore) with math.max, using getchildren()..idk what to do?

Asked by 9 years ago

i have it scripted so every time a player makes a kill or dies it increases or decreases the value of a numbervalue. the number value is named after the player so the script can easily match who's score is who's. at the end of the game i'm trying to get the highest score and award that player or players, in-case of a tie. i don't know what to do exactly i've made a loop but it doesn't work for obvious reasons, you'll see, but i am stuck, i don't have the scripting knowledge to do this or i'm going at it the wrong way, here's what i've done.

local highscore
local scores = workspace.killvalues:GetChildren()
for i = 1, #scores do
print(scores[i].Value)
highscore = math.max(scores[i].Value) 
end
print(highscore)

highscore is only receiving one value at a time instead of all the values and like i said, i just don't know what to do. any help is appreciated. ty

1 answer

Log in to vote
0
Answered by
parkderp1 105
9 years ago

You could use table.sort, and use the first value of the table, since it will be the largest, and for a tie you can check if it equals the any of the other values.

Ad

Answer this question