Someone help fix my script

so,I’ve been testing on a script

local highest1 = {}
local votedConcorrents = {"apple","apple","orange","cheese"}
local alreadyMentionedConcorrents = {"name"}

for i,n1 in pairs(votedConcorrents) do
	for l,n2 in pairs(alreadyMentionedConcorrents) do
		print(i,n1)
		if  n1 == n2 then
			print("same")
		elseif not n1 == n2 then
			print("different")
		end
	end
end

it only prints the 7 line.may someone help?

4 Likes

not n1 == n2 would not work. Using not before a variable assumes it is false for any value, but true if the value is false or nil. Simply typing this on the command bar outputs this:

print(not 1) -- false
print(not Vector3.new()) -- false
print(not "true") -- false
print(not true) -- false

print(not false) -- true
print(not nil) -- true

Use parenthesis to correct behavior.

if not (n1 == n2) then -- if n1 is not n2, it is true.

Also, it’s better to type if statements like this instead:

if not (n1 == n2) then
	code here
else -- Else means any other possible outcomes default to here.
	code here
end

Because n1 will never be the same as n2 since no values are the same between both tables…

In the script, you are mentioning two tables:

local votedConcorrents = {"apple","apple","orange","cheese"}
local alreadyMentionedConcorrents = {"name"}

n1 is an element of the first table whereas n2 represents an element of the second table. Since there aren’t any similarities in any of the given tables, n1 and n2 will never be same and thus,

if n1 == n2 then
	print("same")
end

this part will never run. The different part will run every time due to the values never being different.

elseif not n1 == n2 then
	print("different")
end

In fact it should print “different” instead of nothing

1 Like

Change

elseif not n1 == n2 then

To

elseif not (n1 == n2) then