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

Table always prints lowest value using math.max?

Asked by 5 years ago

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.

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

0
Hmm... Didn't seem to work. Here's my full script maybe I did something else wrong. https://pastebin.com/p669KcHk VeryDarkDev 47 — 5y
0
Here's my discord: Mr. Bonesette#6850 VeryDarkDev 47 — 5y
Ad

Answer this question