When to Use Tags Over Attributes

I have recently learned about attributes (ie. the custom fields at the bottom of every object’s properties). After using them for a while, I’ve found that I can achieve everything I can do with tags much more easily with attributes. For example, here’s a shortened version of a script that I wrote a while back that depends on tags:

if part:HasTag("x") then
	vector = Vector3.xAxis
			
elseif part:HasTag("y") then
	vector = Vector3.yAxis
			
elseif part:HasTag("z") then
	vector = Vector3.zAxis
end

It’s somewhat boilerplate-y and I could’ve avoided it all by simply putting the tag into an attribute and using vector = Vector3[part:GetAttribute("Tag")] .. "Axis"]. I can imagine that for more complex scenarios (eg. where there are more tags to check), using attributes would cut it down even more.

So, if using attributes cuts down on this much boilerplate, why do tags exist? Are there hidden advantages to using tags (eg. performance) that I can’t easily see? Or are they just really convenient in enough niche scenarios that I shouldn’t forget about them?

1 Like

It can really depend on your use case. Tags can be used for things like Debounces, and Kill Bricks.

Tags can be used for identifying instances using CollectionService. Instead of adding a bunch of scripts for every kill brick. You can have one script do it all using tags.

Great Video that explains it much more: Youtube Link

Attributes can be used for Custom kinds of “Properties” Although they aren’t really real. They can be used for scripts managing Models. Attributes can tell the server if something needs to happen to a certain object or something should be done in the background using Attributes. There is a wide range of use cases for this.

A Tutorial on how to use Attributes: Youtube Link

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.