How would I enable/disable a widget?

Hello
I am trying to be able to enable/disable widgets. I expected WidgetGUI.Enabled to work, however that wasn’t the case.
Any help would be greatly appreciated. ICrann

   local toolbar = plugin:CreateToolbar("toolbar") 
   local button = toolbar:CreateButton("x", "y", "0")
 
   button.Click:Connect(function() -- the button in the toolbar
   WidgetGui.Enabled = not WidgetGui.Enabled
   end)

For a toggle sort of state, when a button is clicked.

2 Likes

This works but how would I initially hide the it, like immediately when it is created? As I would expect this should work: SetupWidget.Enabled = not SetupWidget.Enabled but it doesn’t.

When you create the widget, change the 2nd argument of DockWidgetPluginGuiInfo.new to false. Example

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)
)
1 Like

I was surprised this didn’t actually work.

I have successfully figured it out thank you everyone that helped.

starting off I would have to do SetupWidget.Enabled = not SetupWidget.Enabled and when the button is clicked I would do SetupWidget.Enabled = true