As a Roblox developer, it’s sometimes annoying to safely refer to instances deep in hierarchy without checking if every ancestor of the instance exists.
Currently
Finding an instance that may not exist
local vehicles = workspace:FindFirstChild("Vehicles")
if not vehicles then return end
local car1 = vehicles:FindFirstChild("Car1")
if not car1 then return end
local vehicleSeat = car1:FindFirstChild("VehicleSeat")
or
local vehicleSeat
pcall(function() vehicleSeat = workspace.Vehicles.Car1.VehicleSeat end)
--[[this would be much more inefficient because it can
silently throw an error which takes dozens of microseconds]]
Waiting for an instance that may exist in the future with a time limit
local timeout = tick()+5
local vehicles = workspace:WaitForChild("Vehicles",timeout-tick())
if not vehicles or tick()>timeout then return end
local car1 = vehicles:WaitForChild("Car1",timeout-tick())
if not car1 or tick()>timeout then return end
local vehicleSeat = car1:WaitForChild("VehicleSeat",timeout-tick())
The problem is that it takes many lines to safely refer to an instance deep in hierarchy, especially when waiting for them.
With QueryDescendant
Accessing an instance that may not exist
local vehicleSeat = workspace:QueryDescendant(">#Vehicles>#Car1>VehicleSeat")
Waiting for an instance that may exist in the future with a time limit
local vehicleSeat = workspace:QueryDescendant(">#Vehicles>#Car1>VehicleSeat",5)
-- the parameter 5 here would be a time limit for waiting
-- none = no waiting
-- -1 = infinite wait
With QueryDescendant it would only be one line, and it wouldn’t throw an error if the instance doesn’t exist, instead it would just return nil.
If Roblox is able to address this issue, it would improve my development experience by making it easier to find or wait for instances deep in hierarchy.