So I'm making a map voting system and the votes are counted as NumberValues for each map but I don't know how to like, get the biggest value/number.
If you have more than two values, to find the biggest value you can use math.max.
math.max(100, 20, 30, 5, 500)
This would return 500, the biggest value in the group of numbers. You can replace these numbers with the NumberValue's values.
Hi awesomejoker248674, comparing values is not as hard as you might think.
To find if a value is larger than another, compare them like so;
Local Value1 = 5 Local Value2 = 1 if Local Value1 > Value2 then print("Value1 is larger than Value2") else print("Value 1 is smaller than Value2" end
The output SHOULD say;
"Value1 is larger than Value2"
If it doesn't, I recommend re-installing your studio, because that's not right at all XD
You can use math.max()
to find the greatest value and math.min()
to find the lowest value.
By the way you are wording it, it would seem that you are using actual value instances, so I suggest this as it will return the value as well as the object. This also works if multiple instances have the same value since it will be saved to a table.
function FindHighestVotes(Folder) local HighestVotes = {{nil}, 0} for _, ValueObj in pairs(Folder:GetChildren()) do if ValueObj.Value > HighestVotes[2] then HighestVotes[1] = {ValueObj}; HighestVotes[2] = ValueObj.Value elseif ValueObj.Value == HighestVotes[2] then table.insert(HighestVotes[1], ValueObj) end end return HighestVotes end for _, Map in pairs(FindHighestVotes(workspace.Values)[1]) do print(Map.Name) end