I'm making a plugin that involves the plugin's control GUI to be added to CoreGui. I want it to work so that if you click the plugins toolbar button, the GUI shows, and if you click it agian, the GUI goes away, and so on (click it again and it shows again). The only problem is I can't figure out how to remove the GUI from CoreGui without destorying it altogether, making it unable to show agian. Here's my current code:
--PLUGIN VARIABLES--
local toolbar = plugin:CreateToolbar("Animation Cam")
local coregui = game:GetService("CoreGui")
local version = script.Parent.Version
local gui = script.Parent.PluginGui
local open = false
--PLUGIN SETUP--
local pluginButton = toolbar:CreateButton("Rig Viewpoint","h","")
--local focusButton = toolbar:CreateButton("Focus","Label","")
--local fixButton = toolbar:CreateButton("Fix","Label","")
pluginButton.Click:connect(function()
if open == false then
gui.Parent = coregui
open = true
elseif open == true then
gui:Destroy()
open = false
end
end)
I should note that I have also tried to make a close button as part of the GUI itself to close it, but for some reason the button didn't work at all. Here was it's code (inside the GUI itself):
local title = script.Parent.title
local close = script.Parent.Close -- close button
local coregui = game:GetService("CoreGui")
title.Text = "-Rig Viewpoints (V"..script.Parent.Parent.Parent.Version.Value..")-"
local rigs = game.Workspace:FindFirstChild("Rigs")
if not rigs then
local text = Instance.new("TextLabel")
text.Size = UDim2.new(1,0,0.15,0)
text.Position = UDim2.new(0,0,0.4,0)
text.Text = "ERROR: No Rigs folder detected"
text.Name = "ERROR"
text.Parent = script.Parent
end
local viewpoints = game.Workspace:FindFirstChild("Viewpoints")
if not viewpoints then
local text = Instance.new("TextLabel")
text.Size = UDim2.new(1,0,0.15,0)
text.Position = UDim2.new(0,0,0.4,0)
text.Text = "ERROR: No Viewpoints folder detected"
text.Name = "ERROR"
text.Parent = script.Parent
end
close.MouseButton1Click:connect(function()
script.Parent.Parent:Destroy()
end)
I couldn't get the click function to work at all, even trying to simply make it print "!" to the output wouldn't work, so I'm not sure if there's something special you have to do when coding inside a GUI that's inside CoreGui.
All help is appreciated!

2 comments
What I do is a little more complex but works well. I move the gui while running a setup function which also tracks the connections made. When closed I can reset the gui, disconnect all events and move it back to the plugin folder where it can be used again.
In your case you probably will just clone the gui each time.