ModuleScripts running under a plugin should be able to access said Plugin through the global

As a Roblox developer, it is currently impossible to retrieve the Plugin from ModuleScripts using the plugin global. This is because ModuleScripts under a plugin dont have the global set.

This makes developing modules for plugins that need features from the plugin difficult since we need to rely on wokarounds to retrieve the plugin object which looks messy when reading over code.

Pass in the Plugin handle using a function as such: (The “clean” workaround)

local Plugin

return function(PluginHandle)
  Plugin = PluginHandle
end

Or, use FindFirstAncestoryOfClass or similar member to find the Plugin object.

The issue with the first method is that I need to return and call a function when requiring in a module just to set the Plugin handle in the ModuleScript.

local ModuleThatUsesPlugin = require(script.Module)
-- looks cleaner and performs better than
local ModuleThatUsesPlugin = require(script.Module)(plugin)

The issue with the other method is that FindFirstAncestor isn’t a cheap method when being called in every single module, this method could also break if Roblox changes how code inside Plugins are structured (doubt it since this would make PluginDebugService harder)


If Roblox is able to address this issue, it would improve my development experience because I would be able to work with the Plugin without having to rely on hacky workarounds.

22 Likes

It’s extremely tedious defining the plugin global at the top of every ModuleScript I create under a plugin. It gets even more annoying when I decide to move some things around or create more ModuleScripts and my code fails to run because silly me forgot ModuleScripts don’t naturally have access to the plugin global.

When I started experimenting with plugins a few years ago, I was expecting the plugin global to be accessible within ModuleScripts required by a PluginScript and was caught off-guard when it wasn’t.

I honestly don’t understand why that if a plugin script imports the module, the global is unable to be accessed.