Plugin Fully Works ! But when i click the plugin button again the plugin gui doesn't close

I’m Making A Plugin For Y’all To Use But I Ran Into A Problem… When the gui is on and i click the plugin button it doesn’t close the gui? :thinking: How Can I Solve This ?
Feel free to reply !
here is the script:

local toolbar = plugin:CreateToolbar("Rig Build v1")
local button = toolbar:CreateButton("Rig Build v1", "Build A Rig Easily", "rbxassetid://17117819876")

button.Click:Connect(function()
	local gui = script:WaitForChild("MainGui")
	if gui.Parent == script then
	gui.Parent = game:WaitForChild("CoreGui")
	elseif gui.Parent == game:WaitForChild("CoreGui") then
		gui.Parent = script
	end
end)

script.MainGui.Main:WaitForChild("R15"):WaitForChild("Button").MouseButton1Click:Connect(function()
	local rig = script:WaitForChild("R15")
	local clone = rig:Clone()
	clone.Parent = workspace
	clone.Name = "Rig"
	print("R15 Rig Has Been Inserted.")
end)

script.MainGui.Main:WaitForChild("R6"):WaitForChild("Button").MouseButton1Click:Connect(function()
	local rig = script:WaitForChild("R15")
	local clone = rig:Clone()
	clone.Parent = workspace
	clone.Name = "Rig"
	print("R6 Rig Has Been Inserted.")
end)
1 Like

It is because you are trying to find the gui inside of the script after you moved it to CoreGui. I would do something like this instead:

local gui = script:WaitForChild("MainGui")
button.Click:Connect(function()
	if gui.Parent == script then
	    gui.Parent = game:GetService("CoreGui")
	elseif gui.Parent == game:GetService("CoreGui") then
		gui.Parent = script
	end
end)
1 Like

doesn’t work
11111111111111111

Are there any error messages or warnings?​​­​​­​​­​​­

Infinite yield possible on ‘user_PluginMaker.lua.Script:WaitForChild(“MainGui”)’
but the gui is the child of the script and & it should not happen

Can you post a screenshot of the script and its children in the explorer? Also, are there any other scripts that modify the gui in any way?

1 Like

explorer

Move the local gui = script:WaitForChild("MainGui") somewhere outside of that function/event

1 Like

didn’t change a thing should i just use script:FindFirstChildOfClass(“ScreenGui”) ?

You can try that but it isn’t a good solution if you need to add more guis in the future.

nah this is a rig inserter plugin

1 Like

uhmmm doesn’t work either im trying to close the gui if the plugin button is unselected

Is this the only script in your plugin? The only other thing I can think of is that some script other than the one you sent is moving or modifying the gui.

ye its the only one
1111111111111111

Change your script to this and tell me everything it prints

local toolbar = plugin:CreateToolbar("Rig Build v1")
local button = toolbar:CreateButton("Rig Build v1", "Build A Rig Easily", "rbxassetid://17117819876")

print(script:GetChildren())

local gui = script:WaitForChild("MainGui")
button.Click:Connect(function()
    print(script:GetChildren())
    print(gui.Parent)
	if gui.Parent == script then
	gui.Parent = game:WaitForChild("CoreGui")
	elseif gui.Parent == game:WaitForChild("CoreGui") then
		gui.Parent = script
	end
end)

script.MainGui.Main:WaitForChild("R15"):WaitForChild("Button").MouseButton1Click:Connect(function()
	local rig = script:WaitForChild("R15")
	local clone = rig:Clone()
	clone.Parent = workspace
	clone.Name = "Rig"
	print("R15 Rig Has Been Inserted.")
end)

script.MainGui.Main:WaitForChild("R6"):WaitForChild("Button").MouseButton1Click:Connect(function()
	local rig = script:WaitForChild("R15")
	local clone = rig:Clone()
	clone.Parent = workspace
	clone.Name = "Rig"
	print("R6 Rig Has Been Inserted.")
end)

doesn’t work either
charssssss