I want to index values all at once so I don't have to constantly add if statements like so:
while true do
wait(1)
--all values here--
local part
local light
part = script.Parent:FindFirstChild("Part2")
if part then
light = part:FindFirstChild("SurfaceLight")
end
--------------------------
--index values here--
if part and light then
print("ran")
end
end
----------------------
when there a re a lot of children to index theres going to be a lot of if statements which is not desired as I want everything to be setup at once regardless of how many children there are.
something like this:
while true do
wait(1)
--all values here--
local part = script.Parent:FindFirstChild("Part2")
local light = part:FindFirstChild("SurfaceLight")
--------------------------
--index values here--
if part and light then
print("ran")
end
end
----------------------
unfortunately if "part" becomes nil, an error comes up saying "attempting to index nil with findfirstchild"
is there a way around this to accomplish what I am trying to do?

1 comment
that's awesome this is exactly what I was looking for.