This is based on ezAttribute (my previous version), and is a wrapper for Roblox Attributes getter and setter functions. Originally I wasn’t planning on supporting this too heavily but now I’ve got some competition. This will be the definitive thread for EasyAttribute.
Here’s how it works:
As oppose to using GetAttribute
and SetAttribute
, EasyAttribute lets you fetch and edit them like this.
local EasyAttribute = require(6506183427);
local myWorkspace = EasyAttribute(workspace);
Now you can simply index or set anything in this table to set or get an attribute.
myWorkspace.Number = 100;
And get it by referencing the same index.
print(myWorkspace.Number);
Additionally, you can use :Increment
on number attributes to add the specified amount to them, or 1 if you didn’t specify.
myWorkspace:Increment("Number", 10);
The coolest feature is support for strong-typed attributes, attributes that won’t let you change them to a value that isn’t there initial type.
myWorkspace.Number = "Cheese";
To make the above impossible, we’ll use :SetType
with our attribute and the type. true
is dynamic (it can be anything) and false
is strong (it won’t let you change it to something of a type it currently isn’t).
myWorkspace:SetType("Number", false);
myWorkspace.Number = "Cheese";
Last but not least, indexing Raw
will return the actual Instance, which is useful if you want to reference the Instance in a function that has only been passed the EasyAttribute object.
print(myWorkspace.Raw);
And that’s all! I may add more features if I think of any in the future, so definitely request what you would like to see added.
Model:
https://www.roblox.com/library/6506183427/EasyAttribute