Skip to main content

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
Show raw api
{
    "functions": [],
    "properties": [],
    "types": [],
    "name": "Find",
    "desc": "A utility function for finding objects in the data model hierarchy.\n\nSimilar to `FindFirstChild`, except it explicitly errors if any object\nis not found, as well as a more helpful message as to what wasn't found.\n\n```lua\nlocal find = require(ReplicatedStorage.Packages.find)\n\n-- Find instance \"workspace.Some.Folder.Here.Item\":\nlocal item = find(workspace, \"Some\", \"Folder\", \"Here\", \"Item\")\n```\n\nIn 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\"`.\n\nThe return type is simply `Instance`. Any type-checking should be done on the return value:\n```lua\nlocal part = find(workspace, \"SomePart\") :: BasePart -- Blindly assume and type this as a BasePart\nassert(part:IsA(\"BasePart\")) -- Extra optional precaution to ensure type\n```",
    "source": {
        "line": 26,
        "path": "modules/find/init.luau"
    }
}