I came upon this while scripting. I was wondering what it means. I know it relates to the true and false value. But what I'm wondering is that **if you wrote "If "Insert Word Here" would it be equal to false or to true? **
What does If "Insert Word here" then means?
3 answers
Alright so I cant explain it in general words so I will be giving examples and explaining it.
local Part = script.Parent:FindFirstChild("Brick") -- Pretty much just making the "Brick" a local variable named part
if Part then -- checks to see if the Brick even exists
Part.BrickColor = BrickColor.new("Really red") -- Changes the Parts Brick color to the color "Really red"
end
Others gave better examples then I did, and explained it better but I thought I should try to help someone.
Let me give you examples with chunks of scripts
if 1+2 == 3 then
This Chunk checks if 1+2 =3, then it does some stuff.
if not 1+2 == 3 then
This chunk checks if 1+2 does NOT = 3. Why does it check if it doesn't = 3? Because We put a not after if. Not can be used if a object is nil. or if a value false.
local Brick = script.Parent:FindFirstChild("Part")
if Brick then
"If Brick" means if the brick exists. if it was "If not Brick" then that means that the brick does not exist, which in Lua it's nil
local Brick = script.Parent:FindFirstChild("Part")
if Brick then
print("The Brick Was Found!")
if not Brick then
error("We Can't Find The Brick!")
This Checks if the brick does exist, if it does, it prints "The Brick Was Found!"
BUT if the brick does not exist, it errors "We Can't Find The Brick!"
A condition is true if it isn't false and it isn't nil. If the object in the condition exists, the statement is true. If it doesn't exist, it is false.
This discussion is preserved as it was. New answers, comments, and votes are closed.
