Plugin Deactivation Bug

Hello,

My better half and myself have been trying to solve a bug with a plugin I have been working on. The plugin is designed to spawn a part or mesh where clicked. The main function of this works however we haven’t figured out how to tell the code to deactivate properly. Instead, it deactivates but when reactivated, it begins spawning them in 2’s and adds a part/mesh per time the plugin is turned off and on. We’ve spent hours yesterday trying to solve this and we had a hard time finding a solution on the wiki.

This is the deactivation statement which is throwing the error:

plugin.Deactivation:connect(function()
activated = false
plugin:SetActive(false)
end)

“SetActive is not a valid member of Plugin”

Is there a different and proper way of writing this statement?

SetActive is a member of plugin buttons, not the plugin itself. Call this on the button associated with your plugin as opposed to the plugin variable itself.

You don’t use plugin to set active. You use set active on the button. So, instead you would do

local toolBar = plugin:CreateToolbar("PluginName")
local pluginButton = toolBar:CreateButton("PluginButton", "Description", "rbxassetid://123456")

plugin.Deactivation:Connect(function()
    activated = false
    pluginButton:SetActive(false)
end)

The plugin still appears to be having the same issue when its closed and reopened: image The single meshes are spawned during the first use but when I close and reopen the button, it spawns 3 instead of 1.