I want it when I press "q" the GUI appears or disappears for everyone.
01 | function 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 |
13 | end |
14 | end |
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.
01 | function 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 |
05 | end |
06 |
07 | game:GetService( 'ContextActionService' ):BindAction( |
08 | 'GuiToggle' , |
09 | toggleGui, |
10 | false , |
11 | Enum.KeyCode.Q --, |
12 | -- Enum.KeyCode.P -- you can put multiple keys |
13 | ) |
So, if you're using :GetMouse, that's deprecated. You need to use UserInputService. Something like this would work.
01 | UIS = game:GetService( "UserInputService" ) |
02 | UIS.InputBegin:Connect( function (k,gpe) |
03 | if not gpe and k.Keycode = = Enum.KeyCode.q then -- gpe makes sure the player isn't typing |
04 | if Open = = false then |
05 | gui.Enabled = true |
06 | atv.Parent = gui |
07 | Open = true |
08 | else |
09 | gui.Enabled = false |
10 | atv.Parent = game.ReplicatedStorage |
11 | Open = false |
12 | end |
13 | end |
14 | end |
15 | end ) |