Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you use and in a variable?

I was looking in the roblox wiki and clicked :FindFirstChild, and in one of the examples it said:

local myColor = workspace:FindFirstChild("SomePart") and workspace.SomePart.Color

What i'm wondering is how do you use and in a variable?

1 answer

✓ Accepted answer

Basically what this is doing is it is setting the variable called "MyColor" to the color of this part ONLY IF 'SomePart' exists.

If this part doesn't exist, then it would return nil but will not throw an error.

Hope this helps, please let me know if you have further questions.

2 comments

0

What if you have more and's in your variable? Like if you have local Part = script:FindFirstChild("Hi") and script:FindFirstChild("Bye") and workspace.Part

0

You only use this method so the code doesn't error if lets say "SomePart" did not exist, in using this method you will always try to get a property of an instance as the last and, like the example you have, if you want to check for separate stuff like your comment, you can just use an if statement

This discussion is preserved as it was. New answers, comments, and votes are closed.