"If not" confusion

Hello. I know that this is probably really simple to fix, hence why i couldn’t find anything about it on the internet. But the problem is that the script thinks that i mean

local variable = true
if not variable == true then

if not variable. But i want it to mean if not variable == true then do the thing. Thanks!1!

1 Like

You can just do “if not variable then”, don’t need the ==true

1 Like

Just remove the == true and it should work, alternatively you could also replace the == true with == false or ~= true where the swiggly line followed by equal sign means not equal to.

Example:

local variable = true
if not variable then
end
local variable = true
if variable == false then
end
local variable = true
if variable ~= true then
end
2 Likes

It’s scary how our minds are working the same

1 Like

No, the question is just simple. We both only mentioned the most popular answer here.

1 Like

Quick addition to Kat_ie’s post: One reason why people use if not variable in favor of if variable == false is because the latter ( if variable == false) doesn’t work for nil values. Sometimes, Roblox functions return nil instead of false when it can complete whatever task you ask it to do. To check for this, people either say if not variable or if variable == nil. Because us devs are lazy optimal creatures, we generally default to if not variable because of its versatility to work for both boolean and nil values.

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