Hi there, I am learning how to create plugins and I created some code and pasted some of the code of DockWidgetPlugins from the developer wiki
I am trying to create a widget when I click on the button in the toolbar and close it when I click on the [X] button
The error;

The code;
local toolbar = plugin:CreateToolbar("Bababooey")
local button = toolbar:CreateButton(
"name",
"desc",
"2dsa"
)
function PluginCode()
-- Create new 'DockWidgetPluginGuiInfo' object
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
150, -- Minimum width of the floating window (optional)
150 -- Minimum height of the floating window (optional)
)
-- `Create new widget GUI
local testWidget = plugin:CreateDockWidgetPluginGui("testWidget", widgetInfo)
local testButton = Instance.new("TextButton")
testButton.BorderSizePixel = 0
testButton.TextSize = 20
testButton.TextColor3 = Color3.new(1,0.2,0.4)
testButton.AnchorPoint = Vector2.new(0.5,0.5)
testButton.Size = UDim2.new(1,0,1,0)
testButton.Position = UDim2.new(0.5,0,0.5,0)
testButton.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton.Text = "Click Me"
testButton.Parent = testWidget
end
function ButtonClicked()
PluginCode()
end
button.Click:connect(ButtonClicked)
I am 100% sure that I am doing something wrong here, though I dont exactly know what.
Any help is appreciated!
(I have not attempted working with that CreateDockWidgetPluginGui, so I am reading the docs, and trying to think of things that could make that error.)
Are you showing the entire code in your post? - I ask, because in the screenshot of the error you show, it says “TestWidget”, where as in your code it says “testWidget”. So that is a difference.
Could it be, that your plugin contains more than just one Script? - Because “line 22” does not correspond to your code’s call to plugin:CreateDockWidgetPluginGui() … if we can assume that you have copied the content of your Script verbatim, into your posted topic here.
You could possibly also add some print statements, both in your function PluginCode and elsewhere, so you get indications (in the Output-panel) of when and where your plugin-script executes, when you install it into Roblox Studio.
Sorry for the late reply.
I had changed the code a little by testing some other stuff and pasting here and the old Error
I will update it real quick
The error;

code;
local toolbar = plugin:CreateToolbar("Bababooey")
local button = toolbar:CreateButton(
"name",
"desc",
"2dsa"
)
function PluginCode()
-- Create new 'DockWidgetPluginGuiInfo' object
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
150, -- Minimum width of the floating window (optional)
150 -- Minimum height of the floating window (optional)
)
-- Create new widget GUI
local testWidget = plugin:CreateDockWidgetPluginGui("testWidget", widgetInfo)
local testButton = Instance.new("TextButton")
testButton.BorderSizePixel = 0
testButton.TextSize = 20
testButton.TextColor3 = Color3.new(1,0.2,0.4)
testButton.AnchorPoint = Vector2.new(0.5,0.5)
testButton.Size = UDim2.new(1,0,1,0)
testButton.Position = UDim2.new(0.5,0,0.5,0)
testButton.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton.Text = "Click Me"
testButton.Parent = testWidget
end
function ButtonClicked()
PluginCode()
end
button.Click:connect(ButtonClicked)
Ok I fixed it
local toolbar = plugin:CreateToolbar("Bababooey")
local button = toolbar:CreateButton(
"name",
"desc",
"2dsa"
)
-- Create new 'DockWidgetPluginGuiInfo' object
local widgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Float, -- Widget will be initialized in floating panel
false, -- 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
150, -- Minimum width of the floating window (optional)
150 -- Minimum height of the floating window (optional)
)
local testWidget = plugin:CreateDockWidgetPluginGui("testWidget", widgetInfo)
local testButton = Instance.new("TextButton")
testButton.BorderSizePixel = 0
testButton.TextSize = 20
testButton.TextColor3 = Color3.new(1,0.2,0.4)
testButton.AnchorPoint = Vector2.new(0.5,0.5)
testButton.Size = UDim2.new(1,0,1,0)
testButton.Position = UDim2.new(0.5,0,0.5,0)
testButton.SizeConstraint = Enum.SizeConstraint.RelativeYY
testButton.Text = "Click Me"
testButton.Parent = testWidget
function PluginCode()
testWidget.Enabled = true
end
function ButtonClicked()
PluginCode()
end
button.Click:connect(ButtonClicked)
I only need to create a widget one time, not everytime I click
4 Likes