Instance Attributes

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:

  • Attributes can be created, edited, and deleted directly within Studio's Properties window.
  • Attributes and their values are saved with your place and assets.
  • Value changes can be viewed in real time and are replicated so that clients can access them immediately.

Specific examples of attribute usage include:

Weapons with attributes such as damage, fire rate, and reload time
Weapons with attributes such as damage, fire rate, and reload time
Vehicle tuning like acceleration and top speed
Vehicle tuning like acceleration and top speed
Additional package or asset metadata such as description, version, and author
Additional package or asset metadata such as description, version, and author

Supported Types

You can store the following types/values in attributes:

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.

  2. In the popup window, enter the attribute Name, select its Type, and click Save.

  3. The new attribute will appear with a default value that you can change just like any other property.

  4. 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.

Create or Modify Attribute

1local weapon = script.Parent
2
3-- Create an attribute
4weapon:SetAttribute("ReloadTime", 3)
5

Getting Attribute Values

To get the value of one existing attribute, call Instance:GetAttribute() on the instance.

Get Attribute Value

1local weapon = script.Parent
2
3-- Create an attribute
4weapon:SetAttribute("ReloadTime", 3)
5
6-- Get current attribute value
7local reloadTimeValue = weapon:GetAttribute("ReloadTime")
8print(reloadTimeValue)
9

Similarly, you can get all attributes of an instance by calling Instance:GetAttributes(). This returns a dictionary of string/variant pairs representing each attribute.

Get All Attributes

1local weapon = script.Parent
2
3-- Create attributes
4weapon:SetAttribute("ReloadTime", 3)
5weapon:SetAttribute("FireSound", "rbxassetid://3821795742")
6
7-- Get all instance attributes
8local weaponAttributes = weapon:GetAttributes()
9for name, value in pairs(weaponAttributes) do
10 print(name, value)
11end
12

Deleting Attributes

To delete an attribute, call Instance:SetAttribute() with a value of nil.

Delete Attribute

1local weapon = script.Parent
2
3-- Delete an existing attribute
4weapon:SetAttribute("ReloadTime", nil)
5

Detecting Attribute Changes

To listen for value changes on one or more attributes:

Listen for Change on Attribute(s)

1local weapon = script.Parent
2
3--- Listen for one specific attribute change
4weapon:GetAttributeChangedSignal("ReloadTime"):Connect(function()
5 print(weapon:GetAttribute("ReloadTime"))
6end)
7
8-- Listen for any attribute change on the instance
9weapon.AttributeChanged:Connect(function(attributeName)
10 print(attributeName, weapon:GetAttribute(attributeName))
11end)
12