Selection problem with my plugin

Hello,

I recently created a plugin for me with a lot of cool tools.
One of them is a gui object converter. We all realized that the image we placed perfectly had to be an imagebutton. My tool allows you to replace it in one click !

But a problem persists !

When I click on the buttons of my gui, I lose my selection (look down below) and my script therefore does not detect the frames that I have to replace

Do you have any solution for fix it ?

Thanks a lot !

The only possible solution here would be to detect selection changes, and save it as a variable. Then check if that selected instance is a valid UI Object, then boom!

For example:

local Selection = game:GetService("Selection")
local lastSelection

Selection.SelectionChanged:Connect(function()
     lastSelection = Selection:Get()
end)

Button.MouseButton1Click:Connect(function()
    --loop through last selection and convert!
end)

Hope this helps. I’ve had similar issues, but with a sort of radio system.

Before performing the action on the button click, save the current selection state. Once the button action is completed, restore the selection state.