I just need to clarify whether module scripts act as a global script that functions can pass requests to, to be calculated, or if they act as scripts that can be 'downloaded' into other scripts to be run locally (essentially embedding).
I was under the impression that they operated similarly to remote events, however some recent code ive been running has been producing duplicate results, leading me to believe that they instead operate internally on the scripts that pull them, and overwrite variables when they are pushed back on completion.
Because of this, im currently using a rand func to assign time to before the functions are being run, so that their is no concurrent function being deployed that would either duplicate or overwrite the data of another in operation. Its not a very good fix, but for the moment it works, but I feel it would fail under a stresstest of multiple players.
If the code is copied out to each script pulling it, and it is infact a central process that is just being passed variables via request function, then il probably move to build a queue system to process each request individually, since theyre small and non time consuming. However if they are as theorised above, then im not sure what to do about my issue that would prevent these issues in an ironclad manor.
function module.Population(oldRegion, newRegion, Player) local x = math.random(10)/10 wait(x + timeOffset) timeOffset = x if buildlock == true then wait(1) module.Population(oldRegion, newRegion, Player) else --Actual code and other functions that I want to trigger
As you can see, im using a boolean statement to control majority of the requests, and an offset variable to manage any events triggered simultaneously. But for all I know, theyre both redundant pending on how these modulescripts actually operated.
Appreciate any solid explanation. Thanks
A module is, by definition, "one of a set of separate parts that, when combined, form a complete whole." Modular programming relies on independent modules to build complex program-structures.
Roblox provides you with the ModuleScript object to write these independent code-files that can be required with Roblox's own require
function. They are no different than any other lua files -- in fact, if you were developing with native lua, you'd have normal lua files work as your modules. A module is executed in the environment it's required in because the modules are there to extend the code running on that very machine.
They are absolutely not scripts running on the server but neither are they repositories. They are simply functions (one module can be thought of as a function (with a cached output) as it has to return a value to the requirer) separated into different files for organization purposes.
A module script acts like a localscript if it's being required from a localscript, and a regular script if required from a regular script.
Hope this helped you.