GUI won't reopen after closing

I have a part that’ll open a GUI, and can be closed as well. But whenever you close it, it can’t reopen. I just don’t understand why it won’t reopen.

Open script:

gui = script.Parent.SelectCart

function onClick(click)
	gui:Clone()
	gui.Parent = click.PlayerGui
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

Close script:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
end)

I would really appreciate the help.

try this

gui = script.Parent.SelectCart

function onClick(click)
local Gui = gui:Clone()
Gui.Parent = click.PlayerGui
end

script.Parent.MouseClick:Connect(onClick)

Seems like it doesn’t want to open at all now.

It works for me

see if this works

local gui = script.Parent:WaitForChild("SelectCart")

function onClick(click)
local NewGui = gui:Clone()
NewGui.Parent = click.PlayerGui
end

script.Parent.MouseClick:Connect(onClick)

Still no, could it be that why it isn’t working is because I have my GUI in the part?

are there any errors in the output?

this is how I have it

Capture

1 Like

Thank you so much! It finally works now!

1 Like

if you want it the way that you did have it then you can use this

local gui = script.Parent:WaitForChild("SelectCart")

function onClick(click)
local NewGui = gui:Clone()
NewGui.Parent = click.PlayerGui
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)