Is there another way to check if a variable exists?

I’m currently trying to define a variable but there’s a problem, as I always do:

if variable then
 -- exist
else
 -- doesnt exist
end

But the problem is that my variable is variable = false so it won’t get past the ifs.

Is there any other way to check if a variable exists?

4 Likes

if variable ~= nil then

else

end

(Someone liked this so I thought I’d add on)

~= means “is not equal to”, so ~= nil means is not nil. ~= true means is not true

5 Likes