Plugin gui opening script

So I created a script that if you click a plugin button on the toolbar it opens a gui that is the main plugin scripts child. And when I test it does not work. Here is the script:

local toolbar = plugin:CreateToolbar("Essentials")

local newScriptButton = toolbar:CreateButton("Launch Essentials", "Essentials -V0.0.1B", "rbxassetid://12375039577")

newScriptButton.Click:Connect(function()
	script:WaitForChild("mainGui")
	if script.mainGui.Parent == script then
		script.mainGui.Parent = game:WaitForChild("CoreGui")
	elseif script.mainGui.Parent == game:WaitForChild("CoreGui") then
		script.mainGui.Parent = script
	end
end)

If you can please help me.

what is the local plugin in?

character slimitasdasdas

Just guessing that it could be because you’re checking script.mainGui.Parent == script. Here I suppose you’re not trying to compare the two instances but check if they are at the same location, and if so do something. But if I am not mistaken you’re checking if the script.mainGui.Parent is the ‘same’ as the script.