Attributable: Easy Attributes

Hello! I’m fairly new to the resource making scene, but I made a nice module that I feel is helpful. This post essentially serves as a documentation and about page for it.

Get It

You can get the script here, and include it like this:

local attributable = require(10943540954)

Attributable


Attributable is a module focused on making attributes easier, with less function calls, easier events, and a more manageable way to do it.

Attributable is mainly just a metatable at it’s heart, so it’s easy to just use it.

Create a AttributeTable:

attributable:CreateAttributeTable(instance : Instance)
Returns the AttributeTable, generated by the instance.

AttributeTable

To use the Attribute table, all you have to do is assign properties to it like a regular instance. For example, here’s assigning hunger and thirst to a player:

local playerTable = attributable:CreateAttributeTable(plr)
playerTable.hunger = 100
playerTable.thirst = 100

-- Or, do it this way:
playerTable["hunger"] = 100
playerTable["thirst"] = 100

print(playerTable.hunger, playerTable.thirst) -- Outputs: 100, 100

Attribute Changed Events

To get an event that fires when an attribute is changed, you call the table as if it were a function, like this:

-- continued from above
playerTable("getEvent", "thirst").Event:Connect(function(attr, val)
    print(attr.." changed to "..val)
end)

playerTable.thirst -= 25 -- prints "thirst changed to 75"

Calling getEvent gives you a BindableEvent to use wherever.
The reason that the first argument is GetEvent is because I’m going to add more utility functions in the future.

That’s it! Thank you for reading. You can get the script here, and include it like this:

local attributable = require(10943540954)

Lastly, please report any bugs, and offer suggestions! I plan to update and improve this module in the future.

7 Likes

module is offsale, so cant get a copy or require it.

3 Likes

Instance Attributes already exists.
Is there any reason to use this?

2 Likes

Seems like you didn’t read the post :upside_down_face:
If I understand correctly, this module makes it easier to work with the existing roblox attributes system. I think this module makes a table of an instance’s attributes so you don’t have to call :SetAttribute() and :GetAttribute() a million bazillion times (an issue I have in my game since it uses attributes for saving)

1 Like

Yo, especially the getevent thing

these kind of stuff are case sensitive, one letter wrong or not the exact caps will not work, to combat this, you can do symbols or some variable in the module like

module.getEvent = "getEvent"

so the auto correct automatically types it and you wont worry about the caps an stuff

playerTable(attributable.getEvent, "thirst").Event:Connect(function(attr, yay)
   print(yay)
end)

Also i noticed you was using bindableevents for events, if you want the module to directly make you connect to the event without having to define Event of the bindable, simply return the bindableEvent.Event

You can also open this in github, i could contribute!

1 Like

My apologies, I was assuming that all this module does is just creating a table with a BindableEvent to detect changes. (The module is not on sale)

1 Like

Please make your module on sale. Thank you.

1 Like

@Wertyhappy27 @DredVoid @pikapower9080 @robloxjw02
Sorry about the offsale thing, I swear I enabled distribution. :sweat_smile:
It’s onsale now!

@commitblue
I might make a different function approach in the future, but for now, it’s going to be like that; for the BindableEvent return, I left it like that so you can reparent it, destroy it, rename it, etc.

2 Likes

why not use a .Changed property

For the attributes? I didn’t use it because it doesn’t work for attributes, and it only works for base instance properties.

What about .AttributeChanged? or :GetAttributeChangedSignal?

1 Like

Those are built into the module; they’re easily accessible by calling the returned table like a function, and it also returns a BindableEvent which lets other scripts call it for util reasons. It also gives the new value, which is a plus.