Skip to content

SpecialKey

export type SpecialKey = {
    type: "SpecialKey",
    kind: string,
    stage: "self" | "descendants" | "ancestor" | "observer",
    apply: (
        self,
        scope: Scope<unknown>,
        value: unknown,
        applyTo: Instance
    ) -> ()
}

When used as the key in a property table, defines a custom operation to apply to the created Roblox instance.

Non-standard type syntax

The above type definition uses self to denote methods. At time of writing, Luau does not interpret self specially.


Members

type : "SpecialKey"

A type string which can be used for runtime type checking.

kind : string

A more specific type string which can be used for runtime type checking. This can be used to tell types of special key apart.

stage : "self" | "descendants" | "ancestor" | "observer"

Describes the type of operation, which subsequently determines when it's applied relative to other operations.

  • self runs before parenting any instances
  • descendants runs once descendants are parented, but before this instance is parented to its ancestor
  • ancestor runs after all parenting operations are complete
  • observer runs after all other operations, so the final state of the instance can be observed

Methods

apply -> ()

function SpecialKey:apply(
    self,
    scope: Scope<unknown>,
    value: unknown,
    applyTo: Instance
): ()

Called to apply this operation to an instance. value is the value from the property table, and applyTo is the instance to apply the operation to.

The given scope is cleaned up when the operation is being unapplied, including when the instance is destroyed. Operations should use the scope to clean up any connections or undo any changes they cause.

Back to top