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

How do I get a GUI to appear and disappear for everyone on the game?

Asked by 6 years ago

I want it when I press "q" the GUI appears or disappears for everyone.

01function PressQ(key)
02    if (key == "p") then
03        if (Open == false) then
04            gui.Enabled = true
05            atv.Parent = gui
06            Open = true
07        elseif (Open == true) then
08            gui.Enabled = false
09            atv.Parent = game.ReplicatedStorage
10            Open = false
11        end
12    end
13end
14 end
0
Are you using the mouse or userinput seith14 206 — 6y
0
mouse AndresaBrasileira 12 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

This is because you are using deprecated code and wrapping your if statements in brackets. Brackets are math exclusive. Lines 2-3 and 7 error due to this. Remove the brackets.

I see you attempted a KeyDown event. Don’t, it’s deprecated. Instead use the UserInputService or ContextActionService. I will use ContextActionService.

01function toggleGui() -- don’t add parameters
02    gui.Enabled = not gui.Enabled
03    -- You don’t need any if statements checking if open or closed! Look @ that!
04 
05end
06 
07game:GetService('ContextActionService'):BindAction(
08    'GuiToggle',
09    toggleGui,
10    false,
11    Enum.KeyCode.Q --,
12 -- Enum.KeyCode.P -- you can put multiple keys
13)
Ad
Log in to vote
0
Answered by 6 years ago

So, if you're using :GetMouse, that's deprecated. You need to use UserInputService. Something like this would work.

01UIS = game:GetService("UserInputService")
02UIS.InputBegin:Connect(function(k,gpe)
03if not gpe and k.Keycode == Enum.KeyCode.q then -- gpe makes sure the player isn't typing
04if Open == false then
05gui.Enabled = true
06atv.Parent = gui
07Open = true
08else
09gui.Enabled = false
10atv.Parent = game.ReplicatedStorage
11Open = false
12end
13end
14end
15end)

Answer this question