Modules don't work correctly when using a plugin

So, I am making a simple plugin script, it requires the module script and done.

The issue is that basically when I load the module it returns the value, but it doesn’t print

Script code:

print(require(game:GetService("ServerScriptService").ModuleScript));

Module code

local module = {};
print("Why dont you work?");
return module;

Saving the plugin as local plugin:
image
Playing the game (or running it):
image

Prints twice since the local plugin and the script are executed when the game is run

Maybe try putting the print outside the local module and return module.

That won’t work (Also tried it), it acts like the modules are loaded lazily, the reason why I posted this is not because of no purpose but because a module returns an incomplete value, I think this is context related and effectively after seeing the print not working it is context related

There is also a problem, and it is I can’t require remote modules from a plugin

I have the answer, so to request a module you need to set the environment the same as the plugin, in this case clone the module script and set the parent to the script parent, now it will fully work

Plugin edit:

game:GetService("ServerScriptService").ModuleScript.Parent = script;
print(require(script.ModuleScript));
1 Like