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

[Module Script] How can I find the largest number in sub tables and return it?

Asked by 5 years ago

Here's an example of what I have set up:

rank1 = {money = 1000, Material = "Fabric", Color = BrickColor.new("Persimmon")}

The above snippet is already in a table.

But how can I return the highest value here back to a script?

This is the part I'm stuck on.

for rank,theranks in pairs(ranks) do

    if theranks.RAP <= tonumber(game.Players[plrName]:WaitForChild("leaderstats").RAP.Value) then

        local highest = math.max(theranks.RAP)

        print(highest)

    end



    end

the issue I'm having is that even when using math.max it returns every value that the players is greater than, and I only want it to return the highest value there.

I'm new to module scripts but heard they're helpful.

so thanks if you can help

0
Define "highest" variable before your for loop. Then print highest out after the loop is done MessorAdmin 598 — 5y
0
or do a table.sort theking48989987 2147 — 5y
0
Thanks for helping! Messor's worked but I appreciate the contribution theking! VeryDarkDev 47 — 5y

Answer this question