plugin:CreateDockWidgetPluginGui is nil

I’m creating a plugin, however it’s telling me that plugin is nil. Do you guys have any advice?

local function createGUI()

	-- Create new DockWidgetPluginGuiInfo
	local widgetInfo = DockWidgetPluginGuiInfo.new(
		Enum.InitialDockState.Float,  -- Widget will be initialized in floating panel
		true,                         -- Widget will be initially enabled
		false,                        -- Don't override the previous enabled state
		200,                          -- Default width of the floating window
		300                           -- Default height of the floating window
	)

	-- Create a DockWidgetPluginGui
	local dockWidgetPluginGui = plugin:CreateDockWidgetPluginGui("DuplicateRemoverGUI", widgetInfo)

On the last line it’s printing

attempt to index nil with 'CreateDockWidgetPluginGui'

Plugin is not available in normal scripts.

I’m aware. This is a plugin script.

Quick question: Is this a module script?

If that’s the case then I believe the problem relies on the plugin global that does not replicate to module scripts. The plugin global is only present in the script that you save as the PluginScript

If so, then luckily the answer is simple. You just need to make your module return a function and pass the plugin object as an argument:

return function(plugin)
--Stuff here
end

And call like this:

require(myModuleScript)(plugin);
1 Like

Oh sweet, had no idea. Thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.