Skip to main content

optional

Sets up require.optional("Name").

Errors are still preserved because Roblox reports errors of module scripts regardless of caller execution context.

local BasicPane = require.optional("BasicPane")

Functions

optional

optional.optional(
_requirefunction,
_modulestring | number | Instance
) → T?

Optional require, if the instance does not exist, or errors while loading, then nil is returned.

Show raw api
{
    "functions": [
        {
            "name": "optional",
            "desc": "Optional require, if the instance does not exist, or errors while loading, then\nnil is returned.",
            "params": [
                {
                    "name": "_require",
                    "desc": "",
                    "lua_type": "function"
                },
                {
                    "name": "_module",
                    "desc": "",
                    "lua_type": "string | number | Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 24,
                "path": "src/optional/src/Shared/optional.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "optional",
    "desc": "Sets up `require.optional(\"Name\")`.\n\nErrors are still preserved because Roblox reports errors of module scripts regardless of caller\nexecution context.\n\n```lua\nlocal BasicPane = require.optional(\"BasicPane\")\n```",
    "source": {
        "line": 13,
        "path": "src/optional/src/Shared/optional.lua"
    }
}