Picking Greatest Value

I am trying to make a voting system, (which we are all probably aware about), but once a certain amount of time has passed, the script will pick the greatest value, and that value will be the map that will be chosen.

Any help will be appreciated!

You can get the greatest value by doing this :

local GreatestValue = 0

for v, Value in pairs(TABLEWITHTHEVOTES) do
	if Value < GreatestValue then
		SmallestValue = Value
	end
end

Have a nice day !

If you have a variable for each map and add 1 for every vote cast, you could then compare values after the vote ends and choose the largest one. i.e

local largest = 0
for i,v in pairs(variables) do
  largest = math.max(largest, v)
end

Every time a voter casts a vote I would make it so that a remote event is fired which updates one of the map selections allowed from server side.

I’m sure that would work, but I should’ve explain more clearly.

I want the greatest value out of 2 other values.

Kind of like the basic voting system in round based games.
(hopefully this made it more clear)

1 Like

Otherwise, the idea purveyed previously is exactly the same in terms of execution.

1 Like

Ive never used the math.max function, does it get the largest value out of the table?

Of two values it selects the largest.

You can make a table, like this :

local Map1Votes = --YOUR VARIABLE FOR THE VOTE
local Map2Votes = --YOUR VARIABLE FOR THE VOTE
local Map3Votes = --YOUR VARIABLE FOR THE VOTE
local MapsVotesTable = {Map1Votes, Map2Votes, Map3Votes}
local GreatestValue = 0

for v, Value in pairs(MapsVotesTable) do
	if Value < GreatestValue then
		SmallestValue = Value
	end
end

Thank you so much, I’ve never used this in one of my scripts so I appreciate it!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.