Table support for Attributes

As a Roblox developer, it is currently too hard to apply complex state to an Instance using Attributes.

Attributes are a great step in the right direction for being able to associate data with instances, however I would like to see support for tables released as well.

My use case is that, I frequently have complex state for my players that I need synchronized between the server and client. For example, say I have the following state table:

{
  items = { { id, name },
  inventory = { id1, id2, id3 },
  money = 0,
}

Currently, I have to send data like this through remotes to sync it up, and it gets complicated trying to juggle that. Since I typically have nested data, I can’t easily use Attributes to have this data applied via Attributes either. It would be convenient for me to be able to attach that type of state table to its respective player, so that it easily replicates to each client when I make changes, and so I don’t have to think about juggling the usual networking required for this.

If Roblox is able to address this issue, it would improve my development experience because I would no longer have to deal with complicated networking to sync up a player’s state with the server and other other clients.

Attributes are a perfect avenue for automatically replicating data, and I know tables have been in the pipeline for getting support, so I wanted to throw in my use case to hopefully get this feature prioritized.

50 Likes

Hi @vocksel, I would like to ask what are the data types that you need for Tables to support when added as an Attribute?

I might decide to add this functionality to AttributeService as a temporary solution until Roblox officially supports Tables.

I have attempt this before and it wasn’t easy at all and you are better off using Remotes anyways due to Dependency reasons.
(I can really understand why Instances and Tables are not supported upon Attributes official released.
In short you have to serialize and support a lot of data types which makes it very complex)

I do support this feature request and definitely would like to see Tables, Instances and CFrames support soon, however if you require complex Tables to replicate then using Remotes is your best option, especially when data changes very frequently.

3 Likes

I think where something like this gets hairy is when you get to the replication side of things. One would think that a table is a really obvious feature that Roblox could easily add in with everything else, but when it comes to replication, you can see why something like this would be tough to do.

There was actually a post about a TableValue Instance but as you can see in the comments, replicating the table would require putting the table in JSON format (which gets rid of certain metadata like colors, functions, etc) or creating a custom replication system, which would quickly turn into a huge job for roblox and can already be implemented by devs in Lua.

So it’s probably not impossible, but just a lot harder than it seems, and that’s why Roblox hasn’t prioritized something like this (although it would be really nice to use instead of ModuleScripts that can cause memory leaks if used improperly).

5 Likes

Your right there could be some issues with replication. My solution is make it non replicatable. Many values and properties in Roblox are not replicated to clients. I think most use cases for attributes with table values are to store inventory data or similar stuff which usually is not necessary to be automatically replicated.

2 Likes

Would love to have simple arrays for attributes, an example would be an ItemSpawner that has an array of strings of items it can spawn, rather than just one single item.

2 Likes

Why don’t you just split the string using string.split…? Your use case isn’t valid.

Using string.split for this case is hacky and ugly, it would be nicer to have built in support rather than have to find hacky ways around it.

2 Likes

Sounds like a you issue on that, there’s no point in an array on attributes.

Are you alright? So to make an inventory system you have to string.split commas ‘,Dog,Cat,Cat,Dog’, whatever that’s annoying but its bearable, but what if you need to add attributes to each pet? Then it gets stupidly complicated.
So you’d need to know all the attributes of the pet before deleting it so you could string.gsub it, and then if you need to update the attributes you need to know the exact attributes, and then update it with the new ones. So you have to code the entire json.encode and decode yourself.

And if you have a quest system, then you need multiple sections, eg for the quest progress, quest objective, and you need another layer if you have multiple tasks per quest.

Well then why not just use Json.Encode and Json.Decode 1) Adds more complexity, but its bearable. 2) What if a dev is half way through coding their inventory system, realise its way to complicated so they want to find another way to do it to make scripting for the rest of the project easier, and then realise Json.Decode and encode exist. They have to code the entire thing again!

I would much rather have this than any of the other stuff Roblox is prioritizing right now.

just use remote events bro, and to replicate an entire table is far more inefficient than to just send changes

You’re right, but there was no one to tell me that a few months ago. Having to update a ModuleScript and send a RemoteEvent every time you want to make change or read a variable just because you want to access an array between scripts is very counter-intuitive, also having the send a RemoteEvent every time you want to read it is ineficient so you have to store it in a client-side module scri- SO TIME CONSUMING… just give me tablevalue please so I can use it like IntValue and everything else :frowning:
Can I just have a way to send a table over multiple scripts without having to make a whole script to do that also Roblox Studio is supposed to be a user-friendly engine?

Which is more efficient RemoteEvents or JSON.Decode/Encode? Isn’t sending like 10RE/s bad? I’m finished with using stringvalues so I’m going to change every script.