What’s the difference between using an attribute and just a normal variable, I see that both provide identical results perhaps the only benefit I see in my opinion of attributes is that you can access them from other scripts easier than variables, is this correct? Is there something I’m missing?
Alright, so for the most part attributes are just like variables but better. The features they have are similar to almost the exact same, imo they’re easier to edit/create while scripting since you don’t have to reference an actual variable. By the way, I’m assuming by what you mean by normal variables are object variables such as a numbervalue, stringvalue, etc.
They’re also more clean and organized. A good community tutorial would be this one.
If you are speaking about variables, as in a local variable that you make in a script, the difference is like night and day between them.
I’m going to take the opposite assumption that you are talking about local variables inside a script. The difference between them is that a local variable inside a script is attached to that script. It’s managed by that script internally and no other script can access it directly (We are ignoring module scripts for simplicity). Attributes on the other hand are like properties. They are data attached to a part under a given name. Just another “property” like thing that your script can change.
Accessing/editing attributes is significantly slower than accessing/editing a variable.
Could I say if I wanted to access local variables from another script and don’t want to create and manage a module script, I should use attributes? So they serve as a substitution to creating module script to access variables from other scripts
You could technically do that yes. But attributes are meant to be more like a property than a variable. It’s data that is attached to a specific object. A variable however is more data that a script is actively using. Both work, but attributes are more like replacing number Values and stuff so you can attach that data directly to an object instead of making it a child.
Like say you made an obby with kill bricks. But instead of killing they just damage you. Different bricks damage you a different amount. You could make an attribute called Damage and have it be a number. So now you can just adjust this new “Damage” property for each of the bricks to change how much damage it will do (because the script will check). Problems like that are closer to what this is actually meant for. You can however do much more with them. Just as noted by someone else a bit earlier, they are slower to read than a variable.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.