Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Visiblity [closed]

Asked by
Nytroz 15
10 years ago

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

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
jobro13 980 Moderation Voter
10 years ago

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)
0
Thanks alot mate! This will really help move my game along as it depends on this sort of thing. Nytroz 15 — 10y
0
If you want the code to be cleaner: create a script which handles all your GUIs (like I said). It is handier to do that instead of creating tiny scripts which only handle these events. If you expand your game you will get in trouble with that... (yeah, I got experience with that problem.!). jobro13 980 — 10y
0
I've been trying to make a script that does just that, but I don't know how to make it work. What I've done so far is copied the correct code but changed the parts I need to change. After that I'm stuck. Nytroz 15 — 10y
Ad