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

Can you have Logical operator in FindFirstChild such as or?

Asked by 7 years ago

Can you not have logical operator such as or in FindfirstChild or am I just missing a step?

Local bloon = game.workspace:findFirstChild("Part1"or"Part2") -- reads part1 but when i have only part2 its nil

if bloon then
print("Part exists")

else

print("nil")
end

0
As far as I know, that's not possible; it has to be either 'nil or "TEXT"', I believe, b/c both are strings & not nil values. TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

You're close.

print(nil or 1)--// 1

print(1 or nil)--// 1

print(1 or 1)--// 1

print(nil or nil)--// nil

"Part1"or"Part2" results to "Part1". To fix this, use or with two FindFirstChilds.

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

This article should explain more.

Ad

Answer this question