This is a click button one. What is wrong with it it won't close the scripts!
local pg = game.Players.LocalPlayer.PlayerGui
if script.Parent.MouseButton1Click:connect(onSelect) then
function onSelect()
pg.Gui:Remove()
wait()
end
end
script.Parent.MouseButton1Click:connect(onSelect)
loop(math.huge)

2 comments
Didn't work. It had a red line under your line 2
Strange, when I tested it in the Studio, it worked, I wonder why it has a red line under line 2?