How to referance things multiple layers deep if your not sure they are there?

Im assuming startergui doesn’t load before the player, but anyway, is the correct way to reference an object in starter gui 5 layers deep just saying wait for child a bunch of times or is there a different way?

I mean you could just do :GetDescendants right?

for _,Part in pairs(Model:GetDescendants()) do
       if Part.Name == "MY NEEDED PART NAME" then
             --Your code here
       end
end

That’s unnecessary, you can just do :FindFirstChild(name, true), the second parameter makes it search for descendants.

@BaseplateB0T If you want to wait for the object, the best way is still to just type :WaitForChild for every child.

Well I heard for the GUI to load first is to put it in ReplicatedFirst as long as the script with it is not in replicated first, But you can use stuff like <Instance>:WaitForChild() or <Instance>:DescendantAdded() which may be pretty useful

Object.OtherObject.AnotherObject.DifferentObject.FinalObject
This will reference the object without checking if it exists.

game:GetService("Workspace"):WaitForChild("Object")
:WaitForChild("OtherObject"):WaitForchild("AnotherObject"):WaitForChild("DifferentObject"):WaitForChild("FinalObject")

This yields until the object has been loaded.
So the answer to your question is yes, you should just use :WaitForChild

This is very inefficient, and won’t wait until the object is loaded. You might as well just reference it anyways.

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