How I Manage Storing Values
Overview
As you can see, the game uses a client-server model, which filters what an exploiter can do on their machine in order to affect the server. I would never store those physical value objects somewhere, as tables can be the replacement for that.
The only way I want the information from the table sent to the client is when the visuals need to be adjusted or updated.
Current Set-up
For my set-up, I create a table called sessionData
which uses keys of the player.UserId
. Then attach some pre-made data under that key, which is also another table. This table will contain the values such as:
- In-game Currency
- Game Progress
- Inventory
Simply create functions for sessionData
to be handled.
How To Retrieve Values From Client?
Simply use a RemoteFunction
, if the signal is coming from the client, which requests for an update of some visuals. RemoteFunction
’s hooked function needs a return (your values here)
to pass it to the client. Then the client script(also LocalScript
) can update something using the value read from it.
Beware that when you want to set values from client to server, make sure you have sanity checks around the passed values. Never-trust-the-client is a great practice against exploiters, who intend to cheat the game by adding up values in their stats.
If the server is the input. Use a RemoteEvent
, pass the value in the tuple argument when using RemoteEvent:FireClient()
. First argument always player.
Values In Player?
Highly against it. Not the best practice out there. Storing it somewhere else would be better, or else it’ll have problems as mentioned in the post above.
Summary
I would not store the values in the player object, I’d preferably store them in a table where I can later on erase when the player leaves without any technical issues.
The advantage of storing them in a table:
- More writing
- Less hierarchy focus around the Explorer
- Technically secure
…but also…
- Easier organisation
- Easier to write values to – if done correctly
Of course, all of this is managed through a hierarchy of ModuleScript
s. Around this is DataStoreService
and the DataStore
, it skips the step of writing all values from the objects into a table to save it.