ValueBases or Remotes for replicating simple strings/numbers

In your opinion, what is the better way of sending data over the server/client boundary for simpler value types such as booleans, strings and numbers.

In my opinion, you should only use remotes for asking the client to do something or receive more complex datatypes such as arrays and dictionaries (even those these could possible be stored with value bases in folders?)

I think ModuleScripts are the best use for this, as their data can be read by both server and client.

Any change made to a ‘state manager’ ModuleScript will not be replicated across the server-client boundary; i.e. if you change one of the values in that ModuleScript on the server, the change won’t apply to the client. I presume you meant using a ModuleScript for static values, which don’t need to change, in which case this is a valid use of them, but I wanted to clarify that you cannot use a shared ModuleScript to replicate changes in data.

There isn’t really a single “best way” (I assuming now that the data originates from the server, is not static, and needs to change during runtime, and the change needs to be replicated to the client). The two most common ways would either be using value objects, such as StringValues etc, or using RemoteEvents to share the state of the data with the client. The first option is easier to implement and maintain for such simple data, since you just have to deal with simple value objects and Changed events. The data will be automatically replicated when it’s changed, and this can be listened to on the client, which is straightforward.

I would only really use RemoteEvents for this if you wanted more control over what data is being replicated to the clients. For example, if Player 1 needs to read data pertaining to their cash, it could be unnecessary to create a Cash object which is replicated to every single player, since just 1 player needs to access that data. It would depend on your needs.

In my opinion, you should only use remotes for asking the client to do something or receive more complex datatypes such as arrays and dictionaries (even those these could possible be stored with value bases in folders?)

In my experience, the majority of my RemoteEvent use has been through asking the server to do something, not the client.

It can be quite difficult to deal with more complicated data such as arrays and dictionaries, and this is where it becomes quite difficult/not worth it to use ValueObjects, and more worthwhile to use RemoteEvents (in my experience, dealing with objects becomes painful). At the same time, you have to be quite thoughtful and intentional with this, especially with large dictionaries of player data: you can’t constantly just send that over without sacrificing network performance, so you need to think about what extent to replicate, and when. (Does the client need to receive the entire dictionary of their saved data, or only what changed since the last time we sent it?)

You could look into state management libaries if you’re interested, like Rodux and I think I’ve seen a few others on the devforum, though I’m not sure if Rodux handles network replication for you.

2 Likes

That is what I meant, and yes it is good to clarify. :slight_smile:

It’s late, and I am tired. I shouldn’t be trying to critically think!