Attribute
Roblox instance attributes.
Functions
Section titled “Functions”__call
Section titled “__call”function Attribute.__call( self: Attribute<T>, instance: Instance): TSyntax sugar for Attribute:get(instance).
Parameters
Section titled “Parameters”self : Attribute<T>
Section titled “self : Attribute<T>”The attribute.
instance : Instance
Section titled “instance : Instance”The instance to get the attribute from.
Returns
Section titled “Returns”The value of the attribute.`
__tostring
Section titled “__tostring”function Attribute.__tostring(self: Attribute<T>): stringMetamethod to transform the attribute into a string.
Parameters
Section titled “Parameters”self : Attribute<T>
Section titled “self : Attribute<T>”The attribute to stringify.
Returns
Section titled “Returns”string
Section titled “string”The string representation of the attribute.`
assert
Section titled “assert”function Attribute.assert( self: Attribute<T>, instance: Instance): TAsserts 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.
Parameters
Section titled “Parameters”self : Attribute<T>
Section titled “self : Attribute<T>”The attribute.
instance : Instance
Section titled “instance : Instance”The instance to get the attribute from.
Returns
Section titled “Returns”The truthy value of the attribute.`
changed
Section titled “changed”function Attribute.changed( self: Attribute<T>, instance: Instance, callback: (new: T) -> ()): RBXScriptConnectionConnects 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.
Parameters
Section titled “Parameters”self : Attribute<T>
Section titled “self : Attribute<T>”The attribute.
instance : Instance
Section titled “instance : Instance”The instance to track the attribute.
callback : (new: T) -> ()
Section titled “callback : (new: T) -> ()”A function to call when the attribute changes, receiving the new value.
Returns
Section titled “Returns”RBXScriptConnection
Section titled “RBXScriptConnection”Can be used to disconnect the callback.`
function Attribute.get( self: Attribute<T>, instance: Instance): TReturns 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.
Parameters
Section titled “Parameters”self : Attribute<T>
Section titled “self : Attribute<T>”The attribute.
instance : Instance
Section titled “instance : Instance”The instance to get the attribute from.
Returns
Section titled “Returns”The value of the attribute.`
function Attribute.set( self: Attribute<T>, instance: Instance, value: T?): TSets the value of the attribute on the given instance.
Parameters
Section titled “Parameters”self : Attribute<T>
Section titled “self : Attribute<T>”The attribute.
instance : Instance
Section titled “instance : Instance”The instance to set the attribute.
value : T?
Section titled “value : T?”The new value to set for the attribute. Can be nil to clear the attribute.
Returns
Section titled “Returns”The value that was set.`