Add plugin variable to module environment

At the moment, when we create a module, and it’s running within a plugin, we don’t have access to the ‘plugin variable’. I have found it increasingly frustrating that it is necessary to return a function with plugin as a parameter as a workaround. This workaround is hacky, whereas including the built-in plugin variable, would allow us to create tidier code, while also increasing the usefulness of modules in Roblox plugins.

Just as an example, if I were to type this in a Script, it would work, however it would not work in a ModuleScript

--Script
print(plugin) --> Plugin

--ModuleScript
print(plugin) --> nil
9 Likes

FWIW: another way you can grab the instance that the plugin global references is by getting the plugin ancestor. I discovered this trick a while back and I prefer it significantly over needing to call any sort of function to pass the reference into the ModuleScript.

local plugin = script:FindFirstAncestorWhichIsA("Plugin")
15 Likes

That’s definitely a lot better, and I’ll probably be using it. However, I still think the plugin variable should be added, for the sake of consistency and not having to create work-arounds such as this one.

2 Likes

What I would like to see is plugin become available to ModuleScripts run as a descendant of a plugin instance at the very least, given that this trick would let you access the instance easily anyway and having an instance be parented under a plugin is a pretty strong indication that we trust the script with plugin-level stuff.

6 Likes