Attributez: Storing values/tables into objects! (READ SOLUTION)

v.0.5, June 26th

– fixed instance leaking
– optimized script

Introduction

Hello there! Ever had trouble storing values into objects easily? Wanted a part to have a hidden name/value?

Well, look no further! Attributez is here to solve your problems!

Notes/Q&A

What's a attribute?

“a quality or feature regarded as a characteristic or inherent part of someone or something.”

basically, a value assigned to an object.

Why use Attributez instead of CollectionService?

Because CollectionService can only tag things, and cannot store values in tags.

IMPORTANT: Attributez will only work in-game, as it is a module.(unlike CollectionService)

Backstory

I tried to use attributes but it wasn’t released yet so it failed miserably

end of story

Setup

First, you will need to get the module from the link below.
Then, move it into ServerScriptService

(in this example I’ll put in the ServerScriptService, but you can put it wherever you like)

Usage

Now, there are 3 functions that are included in this module:

:SetAttribute(instance,attribute,value) -- the instance (eg. a part), the name of the attribute (eg. HiddenName), and the value of the attribute (eg. "Extra Cool Part" )
--// returns nothing

:GetAttribute(instance,attribute) -- the instance, and the attribute
--// returns the specified attribute, will return nil if not found

:GetAttributes(instance) -- the instance
--// returns a table of attributes, and it's respective values

Example

Say, we wanted a part to have a “hidden name”. We would first, require the module.

local ServerScriptService = game:GetService("ServerScriptService") -- gets the server script service
local Attributez = require(ServerScriptService:WaitForChild("Attributez")) -- replace with the path to where you put the module 
-- (P.S wait for child reduces the risk of your module(s) not loading properly.)

Then, we would identify our part, and use the command :SetAttribute() to give it a hidden name!

local Part = Instance.new("Part",workspace) -- your part
Attributez:SetAttribute(Part,"HiddenName","I'm actually a banana")

In order to get our hidden name from the part, we would use :GetAttribute()

local partHiddenName = Attributez:GetAttribute(Part,"HiddenName")
print(partHiddenName) -- "I'm actually a banana"

If we wanted to get ALL the attributes from the part, then we would use :GetAttributes()

local partAttributez = Attributez:GetAttributes(Part)
print(partAttributez.HiddenName) -- I'm actually a banana

Final Notes

That’s about it! Feedback is greatly appreciated. Good day!

Module:

Source code:

9 Likes

Hi @EmeraldLimes!

Thank you for sharing this resource, it is very interesting.

Would you kindly create a link to Source code (preferably Github and/or Pastebin) for people who want to read the source but don’t have any access to a PC or maybe want to contribute to the source

3 Likes

Thanks for letting me know, I’ve added a pastebin link at the bottom now.

Have a good day!

1 Like

Might wanna rename GetAttributez to GetAttributes… might hinder the workflow a little bit. I think Attributes when working with things like this, not Attributez.

2 Likes

Do not use the parent argument while instancing.
Source: PSA: Don't use Instance.new() with parent argument

It was an example, not a piece of code you should use.

1 Like

A better example is better than a bad example

If you actually read the article instead of just the title, it says that Instance.new's second argument is perfectly fine to use if you’re not setting any other properties of the instance. The problem is setting properties after something’s been parented to a descendant of the DataModel, not just using the parameter — they’d remove or deprecate the parameter if it didn’t have any usecases.

That example is fine, since it doesn’t set any properties of the part, it just puts it in the table his attributez use.

9 Likes

Does this module have any benefits compared to using CollectionService?

You can see how it is less than 30 lines of code, wouldn’t recommend using a module that can be written in 2 minutes.

Tags associate a key with an object, whereas attributes associate a key-value relationship with an object. There are probably plenty of benefits to attributes, considered Roblox themselves have been planning to add them:

https://developer.roblox.com/en-us/api-reference/function/Instance/GetAttribute
https://developer.roblox.com/en-us/api-reference/function/Instance/SetAttribute
https://developer.roblox.com/en-us/api-reference/function/Instance/GetAttributes

I’d assume this is just a temporarily alternative to attributes until they get added for real.

2 Likes

@posatta Yes, that is exactly what I was going for.
@Voidage Sure thing. Just added it, thank you for your feedback!
@recanman Why so? Is it wrong to use modules/scripts that have less than 30 lines of code?

Its not wrongs, its just simple. No point, I don’t see any point in using it.

Alright. I respect your opinion.

Have a nice day!

1 Like

You too, it is a nice creation. It seems to be a bit buggy though.

Could you elaborate? I would like to fix said bugs.

Your localAttributez table will leak instances if they are destroyed, since the Instance is used as a strong key to the table. You should probably fix that ASAP.

Fixed it. Thank you for your feedback!

Seems like roblox has released the official version, rendering this module redundant, go use theirs: