I need to set variables in a ModuleScript, but each player has its variable with a different value for example “Money”, I am using module to communicate values with scripts and localscripts in my game because I am using very high values and a “NumberValue” would not support if can you help me i would be grateful.
I know of two ways you can do this.
One, you can “instance” a modulescript by doing a deep copy of it.
so lets say you have something like a table like
local playerData ={}
playerData.moduleInstace = LuaDeepCopy( require("MyModule") )
---
Inside the module, anything you store like
module.myVariable = 1
will be instanced now.
The other way to do it, which is a little bit more “correct”, is to pass a state structure to each call in the module you make, and not store any data in the module table.
So all your module functions would be written like:
module.Update = function(playerData)
sorry but i really don’t understand, can you explain it better?
and if it is possible, give me a code example in a script and a localscript.
When a ModuleScript is first required in a Enviroment A envirment is either a client or the server the module script is ran and the return value is returned to the require()
call. If you require a modulescript on the client the script is ran and the return value is returned
When you call it the second time the Exact same Value is returned. Including the same Memory address for Tables, functions and userdatas. But if you now require on the Server. The module script is ran again because its in a different enviroment, a seperate value is then returned.
A way you can Change it on both the server and client is using Remotes.
if I modify a Variable in the module using a LocalScript, if I want to obtain the variable was it going to be obtained with the LocalScript modification?