Skip to content

Attribute

Roblox instance attributes.

function Attribute.__call(
self: Attribute<T>,
instance: Instance
): T

Syntax sugar for Attribute:get(instance).

The attribute.

The instance to get the attribute from.

The value of the attribute.`


function Attribute.__tostring(self: Attribute<T>): string

Metamethod to transform the attribute into a string.

The attribute to stringify.

The string representation of the attribute.`


function Attribute.assert(
self: Attribute<T>,
instance: Instance
): T

Asserts that the attribute has a valid value on the given instance. If the attribute is not set or its value is falsy, an error will be thrown.

The attribute.

The instance to get the attribute from.

The truthy value of the attribute.`


function Attribute.changed(
self: Attribute<T>,
instance: Instance,
callback: (new: T) -> ()
): RBXScriptConnection

Connects a callback function to be invoked when the attribute’s value changes on the given instance. The callback will receive the new value of the attribute.

The attribute.

The instance to track the attribute.

A function to call when the attribute changes, receiving the new value.

Can be used to disconnect the callback.`


function Attribute.get(
self: Attribute<T>,
instance: Instance
): T

Returns the value of the attribute from the given instance. If there is no attribute, or config.typecheck is enabled and the value does not match the expected type, returns the default value, if any.

The attribute.

The instance to get the attribute from.

The value of the attribute.`


function Attribute.set(
self: Attribute<T>,
instance: Instance,
value: T?
): T

Sets the value of the attribute on the given instance.

The attribute.

The instance to set the attribute.

The new value to set for the attribute. Can be nil to clear the attribute.

The value that was set.`