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

How do I open a gui with visible = true on mouse click?

Asked by 5 years ago
Edited by Shawnyg 5 years ago

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

01local clickDetector = script.Parent
02local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked
03local debounce = false
04 
05clickDetector.MouseClick:Connect(function(player)
06    if not debounce then
07        debounce = true
08        brickClickedEvent:FireClient(player)
09        wait(1)
10        debounce = false
11    end
12end)

That works all fine and dandy until I try to close it. My close script is

1script.Parent.ClickDetector.MouseClick:Connect(function(player)
2    player:WaitForChild("PlayerGui").ScreenGui.Frame.Visible = true
3end)

How would I make it so that these two scripts work together and allow me to both open and close?

0
Also tip, put your code in the squiggly line button thing these ~~ zandefear4 90 — 5y

3 answers

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
5 years ago

You can just use an if statement, I will do it with a text button and you can incorporate it into yours.

1script.Parent.MouseButton1Click:Connect(function()
2if script.Parent.Parent.Frame.Visible == true then
3script.Parent.Parent.Frame.Visible = false
4else
5script.Parent.Parent.Frame.Visible = true

If I helped please accept this answer, feel free to ask any questions!

Ad
Log in to vote
0
Answered by 5 years ago

Simple if statement

01--Server
02local clickDetector = script.Parent
03local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked
04local debounce = false
05 
06clickDetector.MouseClick:Connect(function(player)
07if 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
13end)
14--LocalScript
15local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked
View all 23 lines...
Log in to vote
-1
Answered by 5 years ago

Don't listen to zompsi, it's easier if you just do:

1script.Parent.Activated:Connect(function()
2    frame.Visible = not frame.Visible
3end

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

0
btw, your explanation wasn't very good, you don't need an event or a click detector, just use an event function B0NBunny 11 — 5y

Answer this question