TableValue Instance

The only way for multiple scripts to read and edit a table is to use module scripts at the moment. A value object that holds a table as the value would be much simpler and more useful. For instance, it would allow us to store player data inside a player using only one instance, rather than having to convert it to many IntValue, StringValue, etc. types of objects and folders or storing it in a module script.

I know there probably were some complications that prevented this feature from becoming available, such as tables not being simple values, and being stored in addresses, etc. However, I am sure it is not impossible, and I think it is worth the effort.

15 Likes

The main problem with this is that it would probably copy the table instead of keeping a reference, which would mean that something like

v.Value.key = 5

would do nothing.
And it would likely have problems encoding “mixed tables”, tables with non string and non numeric keys, and cyclic tables.

If it did keep a reference, would it still send a copy over the network? Would it have problems with cyclic references like connections do when a connected function references the instance which the connection is attached to. Would different context levels get copies, because if it’s just keeping a reference then a metatable could be attached which could mean that a CoreScript could reference and accidently trigger a metamethod which would give a script access to RobloxScriptSecurity members.

If you want TableValues to be like a ModuleScript which returns a table, that would be unlike the other value objects since all of the value objects replicate changes (ModuleScripts keep different copies on each client).

1 Like

If it did do that, it would be kind of useless. Keeping a reference would be much more useful, but you can already do that if you make a ModuleScript that returns a table. The only way a TableValue object would be useful is if it could replicate tables from server -> client. That would be extremely useful.

1 Like

And that is the main reason the request was made. For example, when loading player data; if it is a table, it either has to be stored in a module that is replicated, or converted to many value objects and placed inside the player. We need a simpler alternative; let us just create a TableValue object and place it under the player.

1 Like

Convert table to JSON and store in a StringValue? Although you’d lose references to Instances.

1 Like

The idea most likely wouldn’t be hard to implement if the table would be copied once and then never again until re-assigned.

If what you’re requesting however is that its contents would update whenever you make changes to the table and all peers would be able to see it instantly, then that would be really complicated, since it would require keeping track of any changes done to the table (so most likely changing the vm + adding overhead code in functions such as table.insert). Then there’s the issue with what to do if the table was modified and now contains a value which can’t be serialized.

1 Like