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

How do I make a script that opens/closes a gui?

Asked by 11 years ago

Having trouble with this! This script might have a lot of errors:

Opening button:

01function onClicked()
02local open = script.Parent.Parent
03local close = script.Parent.Parent
04open.Visible = true
05if script.Parent.Parent.Visible == true then
06print = ("Opened")
07end
08end
09 
10script.Parent.MouseButton1Click:connect(onClicked)

Closing Button:

01function onClicked()
02local open = script.Parent.Parent
03local close = script.Parent.Parent
04close.Visible = false
05if script.Parent.Parent.Visible == false then
06print =  ("Closed")
07end
08end
09 
10script.Parent.MouseButton1Click:connect(onClicked)

2 answers

Log in to vote
1
Answered by 11 years ago

To start off please fully detail the assets of your GUI

For what i see you're doubling the variable. You're also using it without sense. If a function is the make something true then whatever comes when it is true should be included in the function. Finally, if both functions have one name then the script would break. So use it in separate names. Use it like this:

01local open = script.Parent.Parent
02 
03function Open()
04open.Visible = true
05print = ("Opened")
06end
07 
08function Close()
09open.Visible = false
10print = ("Closed")
11end
12 
13function Connect()
14if open.Visible == true then
15Open()
View all 21 lines...
0
Okay, so mine will work if I use diffrent function names? Operation_Meme 890 — 11y
0
Exactly. SnazzyPine25 5 — 11y
0
Thx Operation_Meme 890 — 11y
Ad
Log in to vote
0
Answered by
red106 0
11 years ago

Open Script

01local Button = script.Parent
02Frame = script.Parent.Parent.Front --This is a example
03 
04 
05function onClick()
06 
07    Frame.Visible = true -- make sure it says true if  you want it to open
08 
09end
10 
11 
12Button.MouseButton1Click:connect(onClick)

Close Script

01local Button = script.Parent
02Frame = script.Parent.Parent.Menu -- this is just a example
03 
04 
05 
06function onClick()
07 
08 
09Frame.Visible = false --leave it false if you want it to close
10 
11 
12end
13 
14Button.MouseButton1Down:connect(onClick)
0
Uhm, okay, but does mine have erorrs? Operation_Meme 890 — 11y

Answer this question