How do I make a script find the NumValue with the Highest Value
Please help me with this, i’m trying to make a Voting System
If you’re referring to a list here, try the following solution:
If you have 2 objects that you just need to compare, a simple if statement with an operator will suffice.
Operator | Description | Example |
---|---|---|
== | Equal to | 3 == 5 → false |
~= | Not equal to | 3 ~= 5 → true |
> | Greater than | 3 > 5 → false |
< | Less than | 3 < 5 → true |
>= | Greater than or equal to | 3 >= 5 → false |
<= | Less than or equal to | 3 <= 5 → true |
This is actually really simple to do, if you have a table of number values then you can use the “table.sort()” function in order to sort all of the values.
local tables = {1, 4, 6, 2, 4, 2, 4, 3, 9, 8, 4, 3, 2, 5, 8, 8, 3, 2, 5, 2, 8, 5 ,4 ,5}
table.sort(tables)
for _, v in pairs(tables) do
print(v)
end
This block of code here will output all of the numbers in ascending order (from smallest to largest).
A more efficient method may be to just get the length of the list and do something similar to tables[length_of_table]
. This would get the last result guaranteed and could even be done in one line.
You’d still need to sort the table of values first for the last item to have any meaning, otherwise you’d just be fetching the last item randomly.