I haven't worked with ModuleScripts in a while, so I'm not sure exactly how they run. I know how to use them (Return something in the ModuleScript and use require() to access what has been returned) Yet I can't remember if the ModuleScript runs how I'm thinking it is.
Let me try to explain...
In this ModuleScript, I have this function:
return function() print(arg1) end
In this LocalScript, I have this in it somewhere:
local arg1 = "This was an argument loaded from the LocalScript, or is the ModuleScript loading the code into me??" local MS = require(game.ReplicatedStorage.ModuleScript) MS()
So, does the ModuleScript just injects its code into the LocalScript? Or does it just run the function within the ModuleScript? I can't really do much of a test since my internet's down and I'm using my Phone.
A ModuleScript can not get values from local values. A ModuleScript only returns values, which are created inside of the ModuleScript environment.
If you need to get values from the script that is require()
-ing it in, consider putting them as function arguments or using getfenv
to scrape the values from the environment. This assumes that the variables are not declared as local.