Plugin Deactivation Help

So, I’m extremely new to working with plugins, but I can’t figure out how to deactivate one via script, I tried the following:

plugin:Activate(false)
plugin:Deactivate()
plugin:Deactivate(true)

But can’t seem to get it right. Could someone help me out?

plugin:Deactivate() should work – what are you trying to do exactly?

Well, the widgets interested me so I tried creating one, but can’t figure out the deactivation part.

local isLoaded = plugin:GetSetting("pluginIsLoaded")
button.Click:connect(function()		
    if isLoaded == false then	
        print("Plugin is now active")
    local info = DockWidgetPluginGuiInfo.new(
        Enum.InitialDockState.Float, -- Window will be initialized in a floating state.
        true,						 -- Window will be initially enabled.
        false,						 -- Don't override the saved enabled/dock state.
        200,						 -- Width of the floating window.
        100							 -- Height of the floating window.
    )    

        local pluginGui = plugin:CreateDockWidgetPluginGui("Test_Dockable_Widget", info)

        local testBtn = Instance.new("TextButton")
        testBtn.TextScaled = true
        testBtn.AnchorPoint = Vector2.new(0.5,0.5)
        testBtn.Size = UDim2.new(1,0,1,0)
        testBtn.Position = UDim2.new(0.5,0,0.5,0)
        testBtn.SizeConstraint = Enum.SizeConstraint.RelativeYY
        testBtn.BackgroundColor3 = Color3.new(1,0.5,0)
        testBtn.Text = "I hope I didn't mess this up!!"
        testBtn.Parent = pluginGui
        plugin:Activate(true)	    
        plugin:SetSetting("pluginIsLoaded", true)		
    else
        print(isLoaded)
        plugin:Deactivate()
        plugin:SetSetting("pluginIsLoaded", false)	 
    end	
end)

PluginGui visiblity is not tied to the activation state of your plugin. “Activating” your plugin just deactivates all other plugins and optionally gives you the StudioMouse. Your PluginGui will work regardless.

If you want your button to just show/hide your PluginGui, then don’t call Activate or Deactivate, as it will mess with other plugins’ activation states, which you don’t want.

You should make your PluginGui at the beginning of your plugin script, then your toolbar button can just toggle the PluginGui’s Enabled property.

2 Likes

If you want to hide the widget, on a PluginGui object set the following property:

PluginGui.Enabled = false

Thanks! I can’t try and fix it at the moment as I need to head off, but I’ll try it out later and let you know if I got it fixed. :slight_smile:

I just tested this out and you don’t even need to save if your PluginGui was enabled. Roblox handles that for you. All you need is a button to toggle the enabled state so that the user can turn it back on if they close it.

Check out this example:

local pluginGui = plugin:CreateDockWidgetPluginGui(
    "Test_Dockable_Widget",
    DockWidgetPluginGuiInfo.new(
        Enum.InitialDockState.Float, -- Window will be initialized in a floating state.
        true,
        false,                       -- Don't override the saved enabled/dock state.
        200,                         -- Width of the floating window.
        100                          -- Height of the floating window.
    )
)
local testBtn = Instance.new("TextButton")
testBtn.TextScaled = true
testBtn.AnchorPoint = Vector2.new(0.5,0.5)
testBtn.Size = UDim2.new(1,0,1,0)
testBtn.Position = UDim2.new(0.5,0,0.5,0)
testBtn.SizeConstraint = Enum.SizeConstraint.RelativeYY
testBtn.BackgroundColor3 = Color3.new(1,0.5,0)
testBtn.Text = "I hope I didn't mess this up!!"
testBtn.Parent = pluginGui

button.Click:connect(function()
    pluginGui.Enabled = not pluginGui.Enabled
end)

You’re also able to develop your GUI in studio, stick it in your plugin script, then do script.PluginMainFrame:Clone().Parent = pluginGui so you don’t have to make the whole GUI by script. Some example code:

local pluginGui = plugin:CreateDockWidgetPluginGui(
    "Test_Dockable_Widget",
    DockWidgetPluginGuiInfo.new(
        Enum.InitialDockState.Float, -- Window will be initialized in a floating state.
        true,
        false,                       -- Don't override the saved enabled/dock state.
        200,                         -- Width of the floating window.
        100                          -- Height of the floating window.
    )
)

local mainGui = script.PluginGuiMainFrame:Clone()
mainGui.Parent = pluginGui
-- your hand-made gui is now inside a plugingui!
-- making guis in Studio is a lot easier than making them by script!

button.Click:connect(function()
    pluginGui.Enabled = not pluginGui.Enabled
end)

Don’t forget to turn on “Show Plugin GUI Service in Explorer” in the settings so that you can inspect your plugin’s GUI.

2 Likes

Thank you so much man, that all worked!!