Detecting if any value(s) repeat in a table

Hello, I’m currently stuck on a little issue I am facing with my voting system. I have got to the point where it would increment 3 int values based on what the players chose and selecting the highest but there is an issue I thought of! (it would increment 1 of the 3)

What if the 3 values equal each other? This is where I am stuck figuring out how I would do this

    local sortedValues = {1,2,3} -- not the real values just an example
	local highestValue = 0

			
			for _,x in ipairs(sortedValues) do -- calculates highest value in the table
				if x > highestValue then
					highestValue = x
					warn(highestValue)
				end
			end

Hints or Solutions of any kind would be appreciated! :smiley:

For every entry in the table, check it against every other entry.

local function NoDuplicates(t)
	for key1, value1 in pairs(t) do
		for  key2, value2 in next, t, key1 do
			if value1 == value2 then return false end
		end
	end
	return true
end

print(NoDuplicates({"hi", "test", 703})) --> true
print(NoDuplicates({"hi", "test", "hi"})) --> false
1 Like