✓ Accepted answer
'if' and 'else' statements are wonderful things. It lets the program knows if a thing is in this condition, do these set of actions.
You can simply have your function laid out like this:
Boolean = true
function ExampleFunc()
if Boolean == true then
Boolean = false
elseif Boolean == false then
Boolean = true
end
end
You can then shorthand the 'if'/'else' statement to save time and become more efficient (very important, and you will understand why).
if Boolean then
Boolean = false
elseif not Boolean then
Boolean = true
end
With not is equivalent to false or nil*. Consequently, the absence of not will make it true*.
*MISCONCEPTION: not actually means the opposite of a boolean value. Remember in math: if you multiply a negative number with another negative number, you will yield a positive number. So
not true == false
not false == true
Since the datatype we're manipulating is a boolean value, you can shorten the elseif statement into an else.
else
Boolean = true
end
Because originally, the if statement says if the Boolean is true. Elsewise, it will be false.
To implement that knowledge into your script, you can have a static boolean variable and the set of ifs and elseifs.
On = false
if On == false then
On = true
Workspace.Shadows1.Transparency = 0
Workspace.shadowlight.PointLight.Enable = true
else
On = false
Workspace.Shadows1.Transparency = 1
Workspace.shadowlight.PointLight.Enable = false
end