A short tutorial about Attributes and how useful they are

by lisachandra

Author Avatar

Attributes are basically simple custom properties on Instances, features include:

Attributes are a great tool to use because they can simplify your workflow for changing important parameters in an instance, and if you're working with a team they can easily modify the values and create new variants without requiring a complete understanding of the underlying code.

To add one manually, you first want to scroll down to the very bottom in the 'Properties' tab whilst selecting an instance.

After that you can just click the 'Add Attribute' button and select any type and value you want to add. (string, number, boolean, etc.)


To change attributes in an Instance from a script:

local Weapon: Model

-- Adding / Setting Attributes
Weapon:SetAttribute("Weight", 7.27)

 -- Getting a value of an attribute
local Weight: number = Weapon:GetAttribute("Weight") -- 7.27

-- Getting all attributes in an instance as a dictionary
local WeaponAttributes = Weapon:GetAttributes() -- { Weight = 7.27, ... }

-- Deleting an attribute
Weapon:SetAttribute("Weight", nil)

Listening for attribute changes:

local ATTRIBUTE_CHANGED_MESSAGE = "Attribute '%s' has been changed to the value (%s)"

-- Listen for a specific attribute change
	print(ATTRIBUTE_CHANGED_MESSAGE:format("Weight", tostring(Weapon:GetAttribute("Weight"))))

-- Listen for any attribute change
	print(ATTRIBUTE_CHANGED_MESSAGE:format(name, tostring(Weapon:GetAttribute(name))))

View in-game to comment, award, and more!