I've read the wiki about ModuleScripts, but it isn't making sense. I mean, do ModuleScripts have to be stored in Workplace or ServerScriptService? (cause the examples are in the Workspace) To me, it reminds of Java and importing libraries.
Is there is difference to it with using Global Functions? And when it states that ModuleScripts will only run once, does that mean:
Also, limitations to ServerScripts and LocalScripts accessing ModuleScripts? (No examples of ModuleScripts being using in Roblox Wiki)
local printModule = require(game.Workspace.MyModuleScript) printModule("Test Print") -- prints "Test Print" to output printModule("Test Print") printModule("Test Print")
Something like this, for example can be called?
I've been using Module scripts a lot recently. I usually just leave mine in the workspace form old habit, but I'm sure they work from serverscriptstorage too.
I've set up modules before so that they contain loops, with hundreds of parts calling the same function and it works perfectly fine.
When calling functions from the Module Script you need to do something like this:
local printModule = require(game.Workspace.MyModuleScript) printModule.printFunction("Test Print")
where printModule looks like:
local printModule = {} function printModule.printFunction(string) print(string) end return MyModule
'it can't be used by any other script after it is called?'
They can be called as many times as you wish but it will ALWAYS return the same result for things like math.random(INT, [INT])
(I advise you make ColdSmokes Answer the Answer for the thread.)