I'm quite new to tables (although with a basic understanding) and was confused when the output would give me both 10000 and 0 when I printed the possible values but when I used math.max all I got was 0.
table.sort(ranks) local plr = game.Players[plrName] local highest = 0 for rank,theranks in pairs(ranks) do if tonumber(plr:WaitForChild("leaderstats").RAP.Value) >= theranks.RAP then print(theranks.RAP) print(math.max(theranks.RAP)) end end --print(highest) print(highest)
the script while not complete will be intended to return a players rank based on certain values.
The method you're trying to use requires two parameters, not just one. You should read more about the different varieties of math functions; especially math.max(), before using them without the full idea of how it can be applied to your Script. You should follow through with this for anything you're unsure about. (Apologies if you had decent knowledge already)
The first parameter is the current value, you referenced as 'theranks.RAP
'. The second parameter is the maximum value the value provided can be reached at when ran through this function. This is missing, this is where highest
would go.
you're also receiving 0
because you asked to print it.
table.sort(ranks) local plr = game.Players[plrName] local highest = --// highest value. for rank,theranks in ipairs(ranks) do --// tip: 'ipairs' is more efficient for table looping! if tonumber(plr:WaitForChild("leaderstats").RAP.Value) >= theranks.RAP then print(theranks.RAP) print(math.max(theranks.RAP, highest)) --// second parameter, don't forget! end end
Hope this helps, if so, don't forget to accept this answer and upvote! Good luck with your tables