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.