I've been trying for quite some time to figure this out myself, but I can just seem to get one GUI to close and another to open when the user clicks a button. From what I can see I don't think there's anything wrong with the script, but maybe someone here does?
My code is as the following:
print("Close button loaded") button = script.Parent window = script.Parent.Parent.Parent.Parent setup = Player.PlayerGUI.SetupUI setup.Visible = false function onClicked(GUI) window:Destroy() setup.Visible = true end script.Parent.MouseButton1Click:connect(onClicked)
And my GUI setup is: http://prntscr.com/2taj4s
This is a funny one and it is hard to debug.
Let's review your code. At first glance, there is nothing wrong with it. However, it does not do it's job. Why? We check the output and see that there are no errors. However,
setup.Visible does not appear to be true, YET the window is destroyed. How is that possible? The only possible explanation is that the script stops executing AFTER the window is destroyed, but BEFORE the setup is set to visible. That means that between these operations something happens that stops the script - and it is not an error.
The only possible explanation then is that the script itself has stopped. And yes, this can be explained by the fact that the script is actually IN the window, meaning that the script itself actually gets destroyed when the window is destroyed.
The fixed code will first make the setup visible and then destroy the window.
It is better though to create one script which handles all your GUIs.
print("Close button loaded") button = script.Parent window = script.Parent.Parent.Parent.Parent setup = Player.PlayerGUI.SetupUI setup.Visible = false function onClicked(GUI) setup.Visible = true window:Destroy() end script.Parent.MouseButton1Click:connect(onClicked)