function PressK(key) if (key == "k") then if (Frame.Visible == true) then Frame.Visible = false elseif (Frame.Visible == false) then Frame.Visible = true end end end mouse.KeyDown:connect(PressK)
just wanted to know whats wrong with this code
Dude you can just say Frame.Visible = not Frame.Visible instead of if's. Its way simpler trust me. Because it makes the value opposite of what it was before. Also just use UserInputService for keydown functions. They are very reliable and they work across PC and Console.
Mouse.KeyDown
is deprecated, and so is connect
. The KeyDown
could be your problem.ContextActionService
or UserInputService
to get user input. Personally, I’d prefer ContextActionService
, mainly because you can bind actions to functions, make mobile exclusive buttons, and bind multiple keys to functions without if
statements.function toggleGui() --don’t include any parameters, as bind action doesn’t allow these. Frame.Visible = not Frame.Visible end game:GetService("ContextActionService"):BindAction( "Toggle", --name of action toggleGui, --function to bind true, --Make a mobile button Enum.KeyCode.K, Enum.KeyCode.E, Enum.KeyCode.F ) --you can just use one if you like, but i want 3