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 4 years ago
Edited by Shawnyg 4 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

local clickDetector = script.Parent
local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked
local debounce = false

clickDetector.MouseClick:Connect(function(player)
    if not debounce then
        debounce = true
        brickClickedEvent:FireClient(player)
        wait(1)
        debounce = false
    end
end)

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

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

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 — 4y

3 answers

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

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

script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Frame.Visible == true then
script.Parent.Parent.Frame.Visible = false
else
script.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 4 years ago

Simple if statement

--Server
local clickDetector = script.Parent 
local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked 
local debounce = false

clickDetector.MouseClick:Connect(function(player)
if not debounce then
    debounce = true 
    brickClickedEvent:FireClient(player)  --Lets the client know the brick was clicked
    wait(1) 
    debounce = false
    end 
end)
--LocalScript
local brickClickedEvent = game.ReplicatedStorage.Events.BrickClicked 
brickClickedEvent.OnClientEvent:Connect(function() --Client detected the click
    local ui = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
    if ui.Visible then --If the ui is visible
        ui.Visible = false --Make it invisible
    else --it is isn't
        ui.Visible = true --Show it
    end
end)

Log in to vote
-1
Answered by 4 years ago

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

script.Parent.Activated:Connect(function()
    frame.Visible = not frame.Visible
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

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 — 4y

Answer this question