Need help with some descendant syntax

Hi,
So ive got a small section of code here which is the start of my while loop

while wait() do
    
    
    for i, descendant in pairs(workspace:GetDescendants()) do

This in essence works fine, however i would like the file path to be workspace.Map.Palace:GetDescendants()) do . However the catch is, the model I have named ‘Map’ only spawns into the Workspace about 20 seconds into the game when my game map is chosen (Therefore when in my game lobby it will come up with the error of Map isn’t a valid member of workspace)
So my question is, how can i rewrite this to call on the descendants of ‘Palace’ but only when the Map model has been added to the workspace? Tried a few different methods but haven’t seemed to get it working so far.
Hope that makes sense

You could check if they exist:

if workspace:FindFirstChild("Map") and workspace.Map:FindFirstChild("Palace") then
   -- both exist, do stuff
end
1 Like

Exactly what i was looking for! I was trying everything around this but couldn’t get it just right. Thanks!

Just use this to wait for the model:

repeat wait() until workspace:FindFirstChild("Map")

Would this have any advantage in terms of taking up less server memory as compared to the method above ? (aka is it better on the server to do it that way?)

I don’t recommend doing that:

cc @J_Roblox28

1 Like

workspace:WaitForChild(“Map”):WaitForChild(“Palace”):GetDescendants()