Plugin widget being created, but not visible

  1. What do you want to achieve? Keep it simple and clear!
    The GUI to be visible when created

  2. What is the issue? Include screenshots / videos if possible!
    I create a plugin widget using DockWidgetPluginGuiInfo.new() and CreateDockWidgetPluginGui(), it creates but it is not visible.
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have used code from the devhub that I used the first time I messed around with widgets and it worked, now it doesnt work at all, yes I updated the plugin, at first I realized its cause I set created to true in the creation function which doesnt work cause after it checks if its false, if it is then it runs the function, that is now fixed, however it still does not get set to visible.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I have not yet to try printing before and after the function gets called, but it surely is considering it prints, im assuming that its being created and not being made visible, however I could be wrong, but it prints before and after it gets created like it is supposed to, so the function is running.

Code
local toolbar = plugin:CreateToolbar(pluginSettings.pluginName)
local toolbarButton = toolbar:CreateButton(pluginSettings.pluginName, pluginSettings.pluginDescription, pluginSettings.pluginImage)
local widgetCreated = false
local widgetOpened = false

-- Functions

local function createWidget()
	if widgetCreated == false then
		-- Create widget
		print("creating")
		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
			150     -- Minimum height of the floating window
		)
		
		local gribraryWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
		gribraryWidget.Title = "Gribrary"  -- Optional widget 
	    print("created")
	end
end

local function openWidget()
	
end

local function closeWidget()

end

toolbarButton.Click:Connect(function(var)
	if widgetCreated == false then
		-- If widget isnt created, then create widget
		createWidget()
		widgetCreated = true
	elseif widgetCreated == true then
		if widgetOpened == false then
			-- Open cause its not open
		elseif widgetOpened == true then
			-- Close close cause its open
		end
	end
end)
1 Like

You don’t need to create a widget everytime the toolbar button gets clicked. Enable the widget simply by using widget.Enabled = true

Example script
local Toolbar = plugin:CreateToolbar("Click me")
local Button = Toolbar:CreateButton("", "", "", "")
local Opened = false

local Info = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Left,
	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 Wid = plugin:CreateDockWidgetPluginGui("", Info)
Wid.Title = ""

Button.Click:Connect(function()
	if Opened then
		Wid.Enabled = false
		Opened = false
	else
		Wid.Enabled = true
		Opened = true
	end
end)
2 Likes

Thanks, I will try using .Enabled, I didnt need to use it before, maybe its studio being buggy
Also I dont think you understood my code (I know it is if statement terror) but this is what I was doing

check if widget is created – > if its not then creates it – > if it is then it checks if its open or closed, if its open, then it will close. if it is closed, then it will open.

1 Like

You don’t need to check if the widget is created then make the widget. Just create the widget in the beginning of the script.

1 Like

I see what you mean, I guess you are right

Just realized that wouldnt work, if I created it in the script instead of when its clicked and checking if its created or not, then it would automatically create ui everytime u load up studio if u have the plugin installed

1 Like

@Dolphin_Worm thank you anyways, I finally got it working… sorta

1 Like