How do i make a boolean and what are they used for?
A boolean is a data type. Booleans have two values, either true or false.
To refer to a boolean, simply do:
local bool1 = true local bool2 = false print(bool1) --> true print(bool2) --> false
There are numerous uses for booleans.
GuiObject Visibility:
local frame = Instance.new("Frame", somewhere) frame.Visible = false --Sets the visibility to false or not visible frame.Visible = true --Sets the visibility to true or visible frame.Visible = not frame.Visible --Since Visible is a **boolean**, using the not before it makes the boolean the opposite of what it currently is print(frame.Visible) --> false, since it was true then set to it's opposite, false
Conditional Statements:
if (condition) then
action
end
Yes the condition is in fact a boolean and whether it is true or false determines if the action is taken. If it is true the action will take place, if it is false then it will not.
Example:
--2 + 2 == 3 returns false so it will not print if 2 + 2 == 3 then print("2 plus 2 is actually three") end --2 + 2 == 4 returns true so it will print if 2 + 2 == 4 then print("2 plus 2 is actually four") end
To learn more:
People would just say that there like true and false. They will return 1 of 2 things, it is either true or false. So
while hi do --they are used in things like this... so while hi = true it will do the loop wait(1) end