Access `plugin` in descendant ModuleScripts

The plugin global is only available in any Script that is directly run by Roblox at a plugin level. If that Script were to require() another ModuleScript, that ModuleScript would not have access to the plugin global. As I understand it, this is done so that the plugin global doesn’t ‘escape’ out into ModuleScripts that have nothing to do with the plugin.

However, 9 times out of 10, the ModuleScript is associated with my plugin, because it lives directly inside of it. So I end up having to do this awful incantation at the top of all of my ModuleScripts:

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

Since you can gain access to the Plugin object via this method anyway, I’d request that the plugin global be accessible to ModuleScripts iff they are descendants of a Plugin.

23 Likes

I support this!

my current workaround for this is passing plugin into the descendants

the reason this should be supported is because Roblox Studio and Developers are evolving thus plugins are capable and required to do more

with an expanding code base we need to keep it organized and clean, the ability to access the plugin global anywhere in a plugin script context would solve help that cause greatly

3 Likes