PcoWSkbVqDnWTu_dm2ix

Instance Attributes

Instance Attributes

5 min

Attributes allow you to customize instances with your own data. They are similar to built-in object properties, but you can create and modify your own attributes for any instance. Key features include:

  • Create, edit, and delete attributes directly within Studio’s Properties window.
  • Attributes and their values are saved with your place and assets.
  • Attributes and their value changes are replicated so clients can access them immediately.
  • Attribute changes can be viewed in real time.

Specific examples of attribute usage include:

Weapons with attributes such as damage, fire rate, reload time, sound IDs, etc.
Vehicle tuning like acceleration and top speed, such as on the endorsed vehicles.
Additional articles/roblox packages|package or asset metadata such as description, version, and author.

Supported Types

Currently, you can store the following types/values in attributes:

  • string
  • boolean
  • number
  • datatype/UDim
  • datatype/UDim2
  • datatype/BrickColor
  • datatype/Color3
  • datatype/Vector2
  • datatype/Vector3
  • datatype/NumberSequence
  • datatype/ColorSequence
  • datatype/NumberRange
  • datatype/Rect

Studio Usage

New attributes can be created and modified in Studio as follows:

  1. Select the instance, scroll to the bottom of the Properties window, and click Add Attribute.
  1. In the popup window, enter the attribute Name, select its Type (string, number, datatype/Vector3, datatype/Color3, etc.), and click Save.
  1. The new attribute will appear with a default value that you can change just like any other property.
  1. If necessary, you can rename or delete an attribute by clicking the gear icon.

Scripting

Attributes can also be created and controlled through scripts.

Creating/Modifying Attributes

To create an attribute or modify an existing attribute’s value, call Instance/SetAttribute with a name and value.

Getting Attribute Values

To get the value of one existing attribute, call Instance/GetAttribute on the instance.

Similarly, you can get all attributes of an instance by calling Instance/GetAttributes this returns a dictionary of string/variant pairs for each attribute.

Deleting Attributes

To delete an attribute, call Instance/SetAttribute with a value of nil.

Detecting Attribute Changes

To listen for value changes on one or more attributes, connect either Instance/GetAttributeChangedSignal (specific attribute) or Instance/AttributeChanged (any instance attribute).

Tags:
  • attribute
  • property
  • customization
  • instance