fdsAttributes, a replacement until Roblox fully adds attributes

In October or November, ROBLOX added a few functions to Instance which allows us to assign values to certain names. Basically, meta-programming

In the 7+ months that these functions have been added, they are yet to be implemented.

fdsAttributes - an alternative to attributes

You can get the module here

Documentation

This module was designed to be as similar as possible to the functions currently available for Instance, bar one function

Functions

void SetAttribute(Instance instance, string attribute, Variant value)

Assigns a new value to the specified attribute for the instance

Variant GetAttribute(Instance instance, string attribute)

Returns the value currently assigned to the attribute for that instance (can return nil)

dictionary GetAllAttributes(Instance instance)

Returns all attributes assigned to that Instance as a dictionary, where the keys are the attribute's name and the value is the value assigned to that attribute

Events

RBXScriptSignal AttributeChanged(Instance instance, string attribute)

Fires whenever an attribute changes for the specified instance
Issues

Replication over the client/server boundary is not possible


This is an issue regarding how modules work, currently, it is not possible to truly replicate attributes over the client server boundary

With a bit of work, I managed to make a small fork to make it replicate
image

GetAttributeChangedSignal is not implemented

This is an intentional choice, use the AttributeChanged event instead
Example
local fdsAttributes = require(ServerStorage.fdsAttributes)

fdsAttributes:SetAttribute(workspace.Part, "TestValue", "hello world")
print(fdsAttributes:GetAttribute(workspace.Part, "TestValue")
--prints out 'hello world'

Feel free to report any bugs if they happen to occur

6 Likes

Good work, but I would be hesitant to make statements like this. You can definitely do Server->Client replication with Remotes. If you are using metatables, its a little more tricky, but not impossible.

1 Like

Wouldn’t attributes assigned to an object that the client can see from the server automatically replicate anyway? or am I missing something

I don’t believe actual attributes would replicate as properties don’t either. The roblox character is a little special though.

This module is merely just a code-based simulation of attributes which ModuleScript environments don’t replicate either. It can be done manually though.

I dont want to stray off topic but, any changes made on the server (that the client can also see) automatically gets replicated (unless stated otherwise). The client cannot affect stuff for other users unless they have NetworkOwnership, which only gives them the ability to replicate CFrame

2 Likes

You’re right. I was being a dumb dumb and thinking about Client->Server replication.
Although ModuleScript environments are still an exception to the Server->Client replication.

1 Like

UPDATE
I added a replication system to the module, the update is now available on the AttributeModule asset

2 Likes