Return it
The thing about ModuleScripts is that they can return values. That means for you that you can simply use the return of the ModuleScript to share values - If you return a table, then you can treat it just like any other table and use it to share variables.
You can however make a function which will make a script share the same global variables as another.
local env = getfenv(0);
local niproxy = function(_,k,v)
env[k] = v;
end;
return function()
local _env = getfenv(2);
local script = _env.script;
for k,v in next, _env do
if k ~= 'script' then
env[k] = v;
end;
end;
setfenv(2, setmetatable({script = script},{__index = env, __newindex = niproxy}));
end;
If you put that in a ModuleScript and then require it and call the function, all global variables will be shared with any other scripts that do the same thing.
1 comment
Edited my answer to add the new code.