Tree
Functions
Find
Similar to FindFirstChild, with a few key differences:
- An error is thrown if the instance is not found
- A path to the instance can be provided, delimited by forward slashes (e.g.
Path/To/Child
) - Optionally, the instance's type can be asserted using
IsA
-- Find "Child" directly under parent:
local instance = Tree.Find(parent, "Child")
-- Find "Child" descendant:
local instance = Tree.Find(parent, "Path/To/Child")
-- Find "Child" descendant and assert that it's a BasePart:
local instance = Tree.Find(parent, "Path/To/Child", "BasePart") :: BasePart
Exists
Returns true
if the instance is found. Similar to Tree.Find
, except this returns true|false
. No error is thrown unless the path is invalid.
-- Check if "Child" exists directly in `parent`:
if Tree.Exists(parent, "Child") then ... end
-- Check if "Child" descendant exists at `parent.Path.To.Child`:
if Tree.Exists(parent, "Path/To/Child") then ... end
-- Check if "Child" descendant exists at `parent.Path.To.Child` and is a BasePart:
if Tree.Exists(parent, "Path/To/Child", "BasePart") then ... end
Await
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Waits for the path to exist within the parent instance. Similar to Tree.Find
, except WaitForChild
is used internally. An optional timeout
can be supplied, which is passed along to each call to
WaitForChild
.
An error is thrown if the path fails to resolve. This will only happen if the path is invalid or if the supplied timeout is reached.
Indefinite Yield Possible
If the timeout
parameter is not supplied, then the internal call to WaitForChild
will yield
indefinitely until the child is found. It is good practice to supply a timeout parameter.
local child = Tree.Await(parent, "Path/To/Child", 30)