Skip to main content

Component

This item only works when running on the client. ClientThis item only works when running on the server. Server

This is the API Documentation for the Component module. Components add functionality to instances with the use of collection service tags.

Functions

new

Component.new(
objectObject,
componentModestring,
argstable
) → Component

Creates a new Component instance, this is used to add functionality to instances with the use of collection service tags.

tip

See the Boilerplates guide to get more component boilerplates.

Usage
local Example = {}
Example.__index = Example
Example.Name = "Example Component"

function Example.new(instance)end

function Example:Init()end

function Example:Destroy() end

local ExampleComponent = Cradle.Component.new(Example, "streamed", {})
return ExampleComponent

Start

Component:Start() → nil

Starts the component, this will initialise the component and bind to the tag.

Usage
local Example = {}
Example.__index = Example
Example.Name = "Example Component"

function Example.new(instance)end

function Example:Init()end

function Example:Destroy() end

local ExampleComponent = Cradle.Component.new(Example, "streamed", {})
ExampleComponent:Start()

Stop

Component:Stop() → nil

Stops the component, this will deinitialise the component and unbind from the tag.

Usage
local ExampleComponent = Cradle.Component.new(Example, "streamed", {})
ExampleComponent:Start()
ExampleComponent:Stop()

GetObjectFromInstance

Component:GetObjectFromInstance(instInstance) → Object

Returns the component object from the instance.

Usage
local ExampleComponent = Cradle.Component.new(Example, "streamed", {})
ExampleComponent:Start()
local ExampleObject = ExampleComponent:GetObjectFromInstance(workspace.Example)
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new Component instance, this is used to add functionality to instances with the use of collection service tags.\n\n:::tip\nSee the [Boilerplates](/docs/boilerplates#component) guide to get more component boilerplates.\n:::\n\n:::note Usage\n```lua\nlocal Example = {}\nExample.__index = Example\nExample.Name = \"Example Component\"\n\nfunction Example.new(instance)end\n\nfunction Example:Init()end\n\nfunction Example:Destroy() end\n\nlocal ExampleComponent = Cradle.Component.new(Example, \"streamed\", {})\nreturn ExampleComponent\n```\n:::",
            "params": [
                {
                    "name": "object",
                    "desc": "",
                    "lua_type": "Object"
                },
                {
                    "name": "componentMode",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "args",
                    "desc": "",
                    "lua_type": "table"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Component"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 115,
                "path": "src/Util/Component/init.lua"
            }
        },
        {
            "name": "Start",
            "desc": "Starts the component, this will initialise the component and bind to the tag.\n\n:::note Usage\n```lua\nlocal Example = {}\nExample.__index = Example\nExample.Name = \"Example Component\"\n\nfunction Example.new(instance)end\n\nfunction Example:Init()end\n\nfunction Example:Destroy() end\n\nlocal ExampleComponent = Cradle.Component.new(Example, \"streamed\", {})\nExampleComponent:Start()\n```\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 157,
                "path": "src/Util/Component/init.lua"
            }
        },
        {
            "name": "Stop",
            "desc": "Stops the component, this will deinitialise the component and unbind from the tag.\n\n:::note Usage\n```lua\nlocal ExampleComponent = Cradle.Component.new(Example, \"streamed\", {})\nExampleComponent:Start()\nExampleComponent:Stop()\n```\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 204,
                "path": "src/Util/Component/init.lua"
            }
        },
        {
            "name": "GetObjectFromInstance",
            "desc": "Returns the component object from the instance.\n\n:::note Usage\n```lua\nlocal ExampleComponent = Cradle.Component.new(Example, \"streamed\", {})\nExampleComponent:Start()\nlocal ExampleObject = ExampleComponent:GetObjectFromInstance(workspace.Example)\n```\n:::",
            "params": [
                {
                    "name": "inst",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Object"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 228,
                "path": "src/Util/Component/init.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Component",
    "desc": "This is the API Documentation for the Component module. Components add functionality to instances with the use of collection service tags.",
    "realm": [
        "Client",
        "Server"
    ],
    "source": {
        "line": 50,
        "path": "src/Util/Component/init.lua"
    }
}