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

How to detect the highest number in a NumberValue?

Im making a voting system for a game but how do I make it so if the value in a number value has more numbers than the other number values?

here is my code where I got stuck

script.Parent.Touched:Connect(function()
	workspace.VotingValues.Shadows.Value = workspace.VotingValues.Shadows.Value +1
end)

if game.Workspace.count.Value == true then
	if workspace.VotingValues.Shadows.Value
end

Thank you if you decide to answer this question

1 answer

You could put all the choices in a table and use table.sort to sort from greatest to least.

local tbl = {}
--if voting is over blah blah then
--for loop in choices do
tbl[choice] = votes
table.sort(tbl, function(a,b) --the second argument of sort is a function that determines how to sort the table
	return a > b -- will either return true or false, if its true, that position will be successfully sorted
end)
tbl[1] = mostvoted -- the most voted will end up being first in the table

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