Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

What does If "Insert Word here" then means?

Asked by
Yeevivor4 155
8 years ago

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? **

3 answers

Log in to vote
1
Answered by
IcyEvil 260 Moderation Voter
8 years ago

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.

Ad
Log in to vote
0
Answered by
Vezious 310 Moderation Voter
8 years ago

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!"

Log in to vote
-1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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.

Answer this question