Plugin cloning twice when I edit parent in script to coregui

I have been having this issue when I change the parent of a screen gui to core GUI it makes 2 copies so there is 2 screenguis of the same thing in coregui. This is messing up a lot of stuff. Any help is great! Thanks! Code Below:

local Toolbar = plugin:CreateToolbar("name") 
local Button = Toolbar:CreateButton("name", "name", "", "name") 
local CoreGui = game:GetService("CoreGui")


local mainscreen = script.Parent
mainscreen.Parent =  CoreGui
mainscreen.Enabled = true
main.NotificationUIText.Visible = true
main.NotificationUIText.Text1.TextTransparency = 1
main.NotificationUIText.Text2.TextTransparency = 1
Button.Click:Connect(function()
	mainscreen.Enabled = not mainscreen.Enabled
end)
1 Like
local duplicate = CoreGui:FindFirstChild(script.Parent.Name)
if duplicate then duplicate:Distroy() end

This checks if there’s an instance with the same name in CoreGui and destroys it if it’s there.

Thanks for trying but this did not work. Do you know why it is cloning it in the first place

You either have another script that clones it or it’s an older version if your plugin that was added from the last time the plugin was run.

where is this ScreenGui placed?

When I am editing it in studio and making the plugin it is in starterGUI. But it moves to CoreGUI when it becomes a plugin

When dealing with UI in plugins, try organizing your plugin like this:
Screenshot (65)

and reference the UI Folder like this:

local Toolbar = plugin:CreateToolbar("name") 
local Button = Toolbar:CreateButton("name", "name", "", "name")

local CoreGui = game:GetService("CoreGui")

local opened = false

Button.Click:Connect(function()

opened = not opened

if opened == true then

local UIFolder = script.Parent.UI:Clone()
UIFolder.Name = "Your UI Folder Name"
UIFolder.Parent = CoreGui
local ScreenGui = UIFolder.ScreenGui

else

local SpawnedUIFolder = CoreGui:FindFirstChild("Your UI Folder Name")

if SpawnedUIFolder then

SpawnedUIFolder:Destroy()

end

end

end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.