Scripts In TextButtons not getting cloned?

So recently, I have been trying to make a plugin.
But once I clone the screengui and set its parent to CoreGui, the scripts apparently, just stop working?

Here is a sample of the script I am using

local Button = Toolbar:CreateButton("Title","Description","Image")
local c = game:GetService("CoreGui"):GetChildren()
local ui = script:WaitForChild("PluginGui")
local clone = ui:Clone()

Button.Click:connect(function()
	for i = 1,#c do

		if c[i].Name == "PluginGui" then

			c[i]:Destroy()
		else
			clone.Parent = game:GetService("CoreGui")
		end
	end
end)

Can someone tell me what I am doing wrong?
Any help would be appreciated.

Is there a script parented under the CoreGui Service? Because remember that scripts do not run when parented under the CoreGui.

No, Its a screengui, with textbuttons as its child, and within the textbuttons are the scripts.

Then the text button scripts are parented under the screengui and therefore is a descendant of the CoreGui?

to specify, the screengui becomes the child of the coregui, and the child of the screengui is a frame, within the frame are textbuttons, and within the textbuttons are the textbutton scripts, so yes.

Then the scripts are under the CoreGui, and like I said they will not run underneath the Service.

Solution?

Server Sided Scripts? Or Local Scripts?

Every script will be dulled underneath CoreGui.

Consider making another script with your main plugin script that handles the buttons but doesn’t need to be parented under the buttons directly.

that’s strange because, if I dont clone the screengui, and just put it as a child of coregui immediately, the scripts work.

All of your scripts should remain as members of the plug-in. Don’t move plug-in scripts around.