Help with MainModule

how could I modify a variable in a MainModule as if it were a LocalScript? (Player only)

for example, if I had a variable ([‘Cash’] = 0) and I wanted it to be one, but only for the player that ran the script?..

1 Like

You can store both local and server values in the same module script.

You would just have to set it’s value locally for it to accept the player. (Set on server to affect server only.)

For example, create a cash adding function. When you call this locally, it will add only to that players variable. Calling it on the server will store it separately. These values can not be transferred or interact with one another inside the module.

sorry but I don’t understand

The only problem with having the MainModule local, on the and/or handled by the client is that exploiters would be able to manipulate the cash variable.
This said your best bet would be to store the data in some sort of table in a module in the server-side. You could create functions to update or retrieve the player’s data when you needed to.

By using the module and its functions from a local script.

Changing this through a local script will only affect the player that changed. it.

Modules are not necessary unless you think you’re going to be repeating yourself a lot. I’d suggest not using a module for something like this, and simply just keeping it all managed on the server, with a RemoteEvent/RemoteFunction to handle interaction. If you’re still adamant on using modules, though, do a little reading on them: ModuleScript | Documentation - Roblox Creator Hub