Find
A utility function for finding objects in the data model hierarchy.
Similar to FindFirstChild
, except it explicitly errors if any object
is not found, as well as a more helpful message as to what wasn't found.
local find = require(ReplicatedStorage.Packages.find)
-- Find instance "workspace.Some.Folder.Here.Item":
local item = find(workspace, "Some", "Folder", "Here", "Item")
In the above example, if "Folder" didn't exist, the function would throw an error with the message: failed to find instance "Folder" within "Workspace.Some"
.
The return type is simply Instance
. Any type-checking should be done on the return value:
local part = find(workspace, "SomePart") :: BasePart -- Blindly assume and type this as a BasePart
assert(part:IsA("BasePart")) -- Extra optional precaution to ensure type