✓ Accepted answer
Instead of using :remove() or :Destroy() I would recommend using the Visible property which is present in Frames, TextLables etc
Assuming "window" is a Frame and not a ScreenGui I would do this:
print("Close button loaded")
window = script.Parent.Parent
function onClicked(GUI)
window.Visible = false
end
script.Parent.MouseButton1Click:connect(onClicked)
Where it says "window.Visible = false" you can change to true and it will become visible again.
Now assuming that this is a ScreenGui and you want to use :remove() I suggest keeping a copy of the ScreenGui in Workspace and using :Clone() and parenting it into the players PlayerGui when you need it to be re-opened.
print("Open button loaded")
window = workspace.ScreenGui:clone()
function onClicked(GUI)
window.Parent = Player.PlayerGui
end
script.Parent.MouseButton1Click:connect(onClicked)
4 comments
..? This doesn't answer his question at all. His question had nothing to do with the script he included.
Sorry, I didn't read it properly, I edited it, hopefully it makes more sense now.
If it needs to toggle on/off, you can just add the line 'window.Visible = not window.Visible' (assuming window is a TextButton). This works because since 'not' reverses a boolean value, the gui's Visible property becomes whatever it currently doesn't equal.
Yeah, i want it to open/close a whole gui using only button, i hope this helps.