Hello everyone. Since there is no TableValue like IntValue or NumberValue instance, I have been saving complex tables as my own formatted StringValues.
But it’s getting too complicated to handle, and wasting a lot of my time as a dev. I know JSON.encode and decode will be a lot easier, but is it as efficient, especially as it is being sent somewhere i think. (because it’s httpservice i dont know)
Or I could use ModuleScripts and use remoteEvents each time a value changes and update the client. But is sending like 10 remoteEvents/sec efficient because of the amount of number changes?
It is not efficient to send an entire table over the network each time a minor component changes. Instead, send the key and value for the client to update. Send the complete table (without encoding it) initially so the client has a copy to work with
The methods JSONEncdoe and JSONDecode do not send the contents to be encoded or decoded anywhere. These functions are only packaged with HttpService because the use of these formats is often associated with HTTP requests.
The correct approach to sending information across the client/server boundary can vary by use case. It is possible to send tables across from server to client or vice versa with some exceptions. If the amount of data is large and the rate of sending updates is frequent, you may want to serialize this data in some form, compressing it before sending on one side and decompressing it on the other side.
It depends on what sort of information your table contains. Could you elaborate on what system is being implemented and what information you expect needs to be replicated?
Again, you’re not likely to send this data more than once. If the inventory changes, only inform the client of what changed—do not send a new copy of the entire inventory. For serializing tables in general, you can look into Squash’s table serialization options
For an inventory system, the server must first send the client the entire contents of their inventory. After this first “sync”, the client only needs to know about changes to the inventory - the client does not need to recieve a copy of their entire inventory every time something changes. However, in order for the client to stay in sync with the server (which holds the trusted copy of the inventory), the server must inform the client every time the inventory changes.
There’s many ways to approach this. A simple approach might incorporate two RemoteEvents:
SyncInventory
UpdateInventory
When a Player joins the game, the server will load their inventory and send its entire contents using the SyncInventory RemoteEvent. Later, after the server applies any changes to the that player’s inventory, it sends an update over the UpdateInventory RemoteEvent.
The payload sent over the SyncInventory RemoteEvent could be the table the server keeps in its entirety, whereas the payload sent over the UpdateInventory RemoteEvent could be two values: the key in the inventory to update, and the new value at that key.
Since the contents of players’ inventories are unlikely to be changing at a high rate, there is probably not much need for serialization.
For me i would create an inventory folder inside of player then i would add items as StringValue refers to items name when player gets items. These items has stringvalue or intvalue childs inside for holding attributes or you can also hold attributes using attribute system in properties section of each item which is my favourite. Then load/save this data on player joins/quits using own datastore system of roblox. You can save tables on this datastore as this hierarchy: playerdata = {}, playerdata[1] = inventory, inventory[1] = item1, inventory[2] = item2… loop the inventory on load/save to get/set items
I store my inventory and quest-targets in stringvalues, but its super annoying and sometimes impossible to work with because you have to use insanely complex string.match sequences which is extremely inefficient
there is a datascript module with plrData and at playerAdded use async remote to transfer plr data to a local script, then use bindable events to transfer the data. Then when updatedata remote is called just update a certain part of the table.
However, I am unsure if it will scale well to large servers, as my game is sort of a clicker game, so 20-60 remote events (data updates) / second wouldn’t work too well.