Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I find the biggest number/value between a couple of number values?

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.

4 answers

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.

1 comment

0

aight thanks ill try it later

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

2 comments

0

the problem is, i have 3 values

0

Oh thats easy, just use math.max

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

This discussion is preserved as it was. New answers, comments, and votes are closed.