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?
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?
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
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
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