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)