Is there a more efficient and easier way to check if an entire instance-path is nil?

So I’ve got this code to check if a player has a certain GUI, but the way I check is getting rather lengthy. I’m also worried about the efficiency of it in the first place, since surely this can’t be good for the server.

if not player.PlayerGui:FindFirstChild("Main") or not player.PlayerGui.Main:FindFirstChild("DialogBox") then return false end
local dialogBox: Frame = player.PlayerGui.Main.DialogBox

What I’m checking in this code bit doesn’t really matter, but I’m asking if there’s a better way to check if (in this case) DialogBox is nil, rather than the baby steps I have to do.

Note: the reason why I have to do baby steps is because it’ll give an error like: “Main is not a valid member of PlayerGui”

You can use recursive FindFirstChild

It has the same functionality but it goes trough all the descendants of an instance

local dialogBox: Frame = player:FindFirstChild("DialogBox",true)

if dialogBox then
  -- do something

Oh wow that’s great! In all honesty I probably should’ve known about the recursive part of that, but this should work perfectly for what I need. Thank you!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.