Can you use "or" when assigning variables?

I couldn’t actually find anything about this online but I’m pretty sure I’ve seen it in tutorials before. Can you do something like this:

local part = workspace.Part1 or workspace.Part2

Or something like this:

local part = workspace:FindFirstChild("Part1") or workspace:FindFirstChild("Part2")

Where if the first part doesn’t exist, it will assign the variable to the second part instead? Do both of the examples work? Is there a better way to do it?

yeah both works, and yeah if it didn’t find “Part1” in workspace and it successfully found “Part2” then it will assign it as the variable

1 Like

This will error if Part1 doesn’t exist under the workspace FYI, but the second example won’t.

2 Likes

yeah right, its necessary to use findfirstchild() for or variables

1 Like