Plugin.Deactivated event firing on Plugin:Activate()

Bug: Calling plugin:Activate() also triggers the plugin.Deactivated event.

plugin.Deactivated is supposed to fire when the plugin should deactivate, either by the means of the player clicking the plugin’s button, or because another plugin has been activated. I bolded that text because I believe that’s the issue. I believe that when a plugin is activated, an internal system is going through and calling Deactivated event on all active plugins, including the plugin just activated (itself).

Whether or not the Activate argument is true or false does not matter.


Temporary template fix (that I kinda stole from @Quenty from some plugin) below:

local button = plugin:CreateToolbar("Blah"):CreateButton("Foo", "Bar", "rbxassetid://1337")
local isOn = false

...

function Off()
	isOn = false
	button:SetActive(false)
end

function PluginButtonClick()
	isOn = (not isOn)
	if (isOn) then
		plugin:Activate(true)
		isOn = true
	end
	button:SetActive(isOn)
	if (isOn) then
		-- On
	else
		Off()
	end
end


function Deactivated()
	if (isOn) then
		Off()
	end
end


button.Click:connect(PluginButtonClick)
plugin.Deactivation:connect(Deactivated)
5 Likes

Apparently this is still an issue 2 years later.

1 Like

This is still an annoying issue that should have a simple fix.

We’re looking into this, but it’s a much larger issue that we may not resolve. The problem being that many plugins bind events on Activated. If we do not call Deactivated first, then when Activated is called again, the events are duplicated.

1 Like

Once again going to point back to this for possible solutions: