Skip to main content

InstanceDataHolder

A very simple class for storing data for instances.

Functions

new

InstanceDataHolder.new() → ()

Creates and returns a new instance data holder.

is

InstanceDataHolder.is(selfany) → boolean

Returns true if the given object is a InstanceDataHolder.

instanceData

InstanceDataHolder:instanceData(instanceInstance) → {[any]any}

Returns the data of the given instance stored in the instance data holder. If it does not exist, then a new one (an empty table) will be created for it and returned instead.

Automatic cleanup

When instance is destroyed, the data stored for it will be automatically cleaned up.

WARNING

instance must not be parented to nil - if so, then this method will throw an error.

cleanupForInstance

InstanceDataHolder:cleanupForInstance(instanceInstance) → ()

Cleans up the given instance's data stored in the instance data holder, if it exists.

TIP

Usually you don't really have to call this method as stored instance data are automatically cleaned up once the instances are destroyed, but this method exists to give the developer more control.

cleanupForAll

InstanceDataHolder:cleanupForAll() → ()

Cleans up all instance data stored in the instance data holder.

destroy

InstanceDataHolder:destroy() → ()

Calls InstanceDataHolder:cleanupForAll and destroys the instance data holder, rendering it unusable.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates and returns a new instance data holder.",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 13,
                "path": "src/InstanceDataHolder/init.luau"
            }
        },
        {
            "name": "is",
            "desc": "Returns `true` if the given object is a [InstanceDataHolder].",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 23,
                "path": "src/InstanceDataHolder/init.luau"
            }
        },
        {
            "name": "instanceData",
            "desc": "Returns the data of the given `instance` stored in the instance data holder. If it does not exist,\nthen a new one (an empty table) will be created for it and returned instead.\n\n:::tip Automatic cleanup\nWhen `instance` is destroyed, the data stored for it will be automatically cleaned up.\n:::\n\n:::warning\n`instance` must **not** be parented to `nil` - if so, then this method will throw an error. \n:::",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ [any]: any }\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 40,
                "path": "src/InstanceDataHolder/init.luau"
            }
        },
        {
            "name": "cleanupForInstance",
            "desc": "Cleans up the given `instance`'s data stored in the instance data holder, if it exists.\n\n:::tip\nUsually you don't really have to call this method as stored instance data are automatically\ncleaned up once the instances are destroyed, but this method exists to give the developer more\ncontrol.\n:::",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 71,
                "path": "src/InstanceDataHolder/init.luau"
            }
        },
        {
            "name": "cleanupForAll",
            "desc": "Cleans up all instance data stored in the instance data holder.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 85,
                "path": "src/InstanceDataHolder/init.luau"
            }
        },
        {
            "name": "destroy",
            "desc": "Calls [InstanceDataHolder:cleanupForAll] and destroys the instance data holder, rendering it unusable.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 97,
                "path": "src/InstanceDataHolder/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "InstanceDataHolder",
    "desc": " \n\nA very simple class for storing data for instances.",
    "source": {
        "line": 6,
        "path": "src/InstanceDataHolder/init.luau"
    }
}