Reconnecting plugin mouse events when plugin is deactivated

Hi. Back again with another plugin-related issue.

I’ve set up connections to mouse events for use with a plugin, but if, for example, I click the Select or Move buttons under the Roblox Home or Model menus (with plugin widget panel still open), the plugin is deactivated (plugin.Deactivation event triggered but widget stays visible) and the mouse connections seem to be lost. There is a WindowFocused() event on the widget that can tell when the plugin regains focus but using plugin:GetMouse() at this point doesn’t seem to return a mouse with the connections intact.

My assumption at this point is that a new PluginMouse object is being created each time the plugin is deactivated/reactivated, and I’ll need to cleanup and reset mouse event connections every time the plugin loses or regains focus (edit: deactivated then re-focused rather). Is anyone familiar enough with how this works to know if that’s the path forward or if there is a simpler solution?

Thanks for your advice.

UserInputService seems to work in Studio. Might be able to do what I need with that. I may be confused about the purpose of the PluginMouse. Since I’m selecting buttons in the plugin and then using the mouse to do things related to the button choice in the workspace, the PluginMouse may not be the right thing to use anyway.

Edit:
Okay, the plugin:Deactivate disables the PluginMouse, so plugin:Activate needs to be called to enable it again. Connections are still good. Adding the following worked for what I needed in case anyone else runs into a similar situation.

-- widget = plugin:CreateDockWidgetPluginGui(...)
widget.WindowFocused:Connect(function()
	if not plugin:IsActivatedWithExclusiveMouse() then
		plugin:Activate(true)
	end
end)

This lets me choose an item via a button in my plugin to add to the workspace with mouse clicks, switch to Roblox selection/move/etc tools to make edits, and then click the plugin widget to pick up where I left off adding things to workspace. Didn’t need to switch over to using UserInputService .

3 Likes