What does __.Value = not __.Value mean?

Found this in a module script and I don’t understand it. Can anyone help? Thanks.

	Circle.Active = not Circle.Active
2 Likes

not basically just inverts it.

for example, in an “If function”

if not 2+2==6 then 
    print("2+2 is not 6!")
end

this function checks if 2+2 is NOT 6, and if it isn’t; continues

3 Likes

therfore, using “not” will just invert the value.

In this case, if

Circle.Active == true

then circle.Active will be set to false, and if it’s false it’ll be set to True

1 Like

They basically invert the value, so if Circle.Active is false, not Circle.Active is true.

And the code is basically setting the property Active to the opposite. So if it’s active, it becomes inactive, if it’s inactive, it becomes active.

An example is like the light switch: If the switch is off, interacting it will turn it on. If the switch is on, interacting with it will turn it off. That’s basically what the code does.

2 Likes

It’s basically the script equivalent of turning on or off a light switch. If the value is true, it flicks off, and if its false its true.

1 Like

If a bool is true it sets it to false, if a bool is false it sets it to true.

1 Like

You would need to bracket the equality check or else it would run as (not 2) + 2 == 6 which errors since you can’t add numbers to booleans.

Code:

if not (2 + 2 == 6) then 
	print("2+2 is not 6!")
end
1 Like

In this case you technically would not need brackets as it the not checks any of the following conditions as one boolean anyway.

No, not would check for 2’s value.

I even ran your code just to check, here’s the output:

If you don’t understand my explanation, just ask.

My version:
image

As a lot of others have said, Value = not Value is for inverting booleans to/from true and false. Some ways this formatting may be of use are in examples like these:

local IsOn = false
PathToButtonPart.ClickDetector.MouseClick:Connect(function()
    IsOn = not IsOn
    if IsOn == true then
        --// Reconfigure systems for the whatever now being ON
    else
        --// Reconfigure systems for the whatever now being OFF
    end
end)
local Value = true
while true do
    Value = not Value
    SomeBindableEvent:Fire(Value)
    task.wait(5)
end

Value = not Value helps cut down on the number of lines and easily forgettable value updates. Know those times you may have done Value = false within the first part of an if statement then Value = true in the else part? Value = not Value eliminates having to do that and puts the value flip outside of the entire if statement, (most likely) making the code easier to read and follow.

I’m mistaken, thank you for the correction

1 Like