So far I have gotten a gui to open and to close but I have a problem. The script I used to open the gui doesn't work with my close script. My open script is
01 | local clickDetector = script.Parent |
02 | local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked |
03 | local debounce = false |
04 |
05 | clickDetector.MouseClick:Connect( function (player) |
06 | if not debounce then |
07 | debounce = true |
08 | brickClickedEvent:FireClient(player) |
09 | wait( 1 ) |
10 | debounce = false |
11 | end |
12 | end ) |
That works all fine and dandy until I try to close it. My close script is
1 | script.Parent.ClickDetector.MouseClick:Connect( function (player) |
2 | player:WaitForChild( "PlayerGui" ).ScreenGui.Frame.Visible = true |
3 | end ) |
How would I make it so that these two scripts work together and allow me to both open and close?
You can just use an if statement, I will do it with a text button and you can incorporate it into yours.
1 | script.Parent.MouseButton 1 Click:Connect( function () |
2 | if script.Parent.Parent.Frame.Visible = = true then |
3 | script.Parent.Parent.Frame.Visible = false |
4 | else |
5 | script.Parent.Parent.Frame.Visible = true |
If I helped please accept this answer, feel free to ask any questions!
Simple if statement
01 | --Server |
02 | local clickDetector = script.Parent |
03 | local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked |
04 | local debounce = false |
05 |
06 | clickDetector.MouseClick:Connect( function (player) |
07 | if not debounce then |
08 | debounce = true |
09 | brickClickedEvent:FireClient(player) --Lets the client know the brick was clicked |
10 | wait( 1 ) |
11 | debounce = false |
12 | end |
13 | end ) |
14 | --LocalScript |
15 | local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked |
Don't listen to zompsi, it's easier if you just do:
1 | script.Parent.Activated:Connect( function () |
2 | frame.Visible = not frame.Visible |
3 | end |
might have an error, haven't done that in a while, but it is simpler than zompsi and is cross platform friendly, just having MouseButton1Click you would imagine just goes for the computer with a mouse
the frame.Visible = not frame.Visible should: do set the visible to the opposite of what it currently is so it would do exactly what zompsi's script does, but simpler