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?
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!
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)
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