Plugin Widget Not appearing

I’m trying to make a plugin that creates a window when you press the button once and deletes it when you press again.

The problem is tho that I can’t see the widget even though it should be. I’m not sure if the widget is just hidden or something or if it just isn’t appearing at all.

-- [ Services ] ----------------------------------
local ChangeHistoryService = game:GetService("ChangeHistoryService")
--------------------------------------------------

-- [ Variables ] ---------------------------------
local ToolBar = plugin:CreateToolbar("2dMapEditor")

local SettingsButton: PluginToolbarButton = ToolBar:CreateButton("Settings", "Settings", "rbxassetid://12659097301")
local EditButton: PluginToolbarButton = ToolBar:CreateButton("Edit", "Edit", "rbxassetid://109205209769753")

local SettingsWidget = nil
--------------------------------------------------

-- [ Functions ] ---------------------------------

local function SettingsButtonPressed()
	
	if SettingsWidget and SettingsWidget:IsA("DockWidgetPluginGui") then SettingsWidget:Destroy() SettingsWidget = nil warn("Destroying")return 
	else
		warn("Creating")
	end
	
	local WidgetInfo = DockWidgetPluginGuiInfo.new(
		Enum.InitialDockState.Float,
		false,
		false,
		200,
		200,
		200,
		200
	)
	
	SettingsWidget = plugin:CreateDockWidgetPluginGui("SettingsWidget", WidgetInfo)
	SettingsWidget.Title = "Settings Widget"
	
end

local function EditButtonPressed()
	warn("Pressed EditButton")
end

--------------------------------------------------

-- [ Execute ] -----------------------------------
SettingsButton.Click:Connect(SettingsButtonPressed)
EditButton.Click:Connect(EditButtonPressed)

SettingsButton.ClickableWhenViewportHidden = true
EditButton.ClickableWhenViewportHidden = true
--------------------------------------------------

This is the code, thanks in advance

Why not just disable the widget instead of destroying/creating one?

--toggles the settings widget in a single line
--(not true = false, not false = true)
SettingsWidget.Enabled = not SettingsWidget.Enabled

I don’t really know what changed it to make it work but I changed the code to this:

-- [ Services ] ----------------------------------
local ChangeHistoryService = game:GetService("ChangeHistoryService")
--------------------------------------------------

-- [ Variables ] ---------------------------------
local ToolBar = plugin:CreateToolbar("2dMapEditor")

local SettingsButton: PluginToolbarButton = ToolBar:CreateButton("Settings", "Settings", "rbxassetid://12659097301")
local EditButton: PluginToolbarButton = ToolBar:CreateButton("Edit", "Edit", "rbxassetid://109205209769753")

local SettingsWidget = nil
--------------------------------------------------

-- [ Functions ] ---------------------------------

local function CreateSettingsWidget()
	local WidgetInfo = DockWidgetPluginGuiInfo.new(
		Enum.InitialDockState.Float,
		false,
		false,
		200,
		200,
		200,
		200
	)

	SettingsWidget = plugin:CreateDockWidgetPluginGui("SettingsWidget", WidgetInfo)
	SettingsWidget.Title = "Settings Widget"
end

local function SettingsButtonPressed()	
	if not SettingsWidget then 
		CreateSettingsWidget()
	else
		SettingsWidget.Enabled = not SettingsWidget.Enabled
	end
end

local function EditButtonPressed()
	warn("Pressed EditButton")
end

--------------------------------------------------

-- [ Execute ] -----------------------------------
SettingsButton.Click:Connect(SettingsButtonPressed)
EditButton.Click:Connect(EditButtonPressed)

SettingsButton.ClickableWhenViewportHidden = true
EditButton.ClickableWhenViewportHidden = true
--------------------------------------------------

But thank you (:

1 Like

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