In StarterGui I have a ScreenGui called "KeyDownGui". In "KeyDownGui" I have a frame called "Box" and a LocalScript. Inside the LocalScript:
Player = game.Players.LocalPlayer Mouse = Player:GetMouse() gui = script.Parent box = gui.Box Open = false Mouse.KeyDown:connect(function(key) if (key == "q") then if(Open == false) then box.Visible = true Open = true elseif (Open == true) then box.Visible = false Open = false end end end)
I want to be able to press "q" to open the frame(Box) in-game, but in-game the frame does not open up, nothing happens! When I am in Roblox Studio and I go to "Test" at the top and then "Play" it works in there...! If yall would help w/ getting it to work NOT IN ROBLOX STUDIO, that would be awesome! Thanks!
First make sure it is a localscript
and is a child of the Player
object or Character
(PlayerGui
).
Your code can be shortened considerably:
Game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(Key)) if Key == "q" then script.Parent.Box.Visible = not script.Parent.Box.Visible end end)
Or the same using UserInputService
Game:GetService("UserInputService").InputBegan:connect(function(Input) if Input.KeyCode= "q" then script.Parent.Box.Visible = not script.Parent.Box.Visible end end
Make a localscript and put it in StarterGui. Then copy and paste this code in it.
thiskey = game.Players.LocalPlayer:GetMouse() box = script.Parent.Box thiskey.KeyDown:connect(function(k) local key = string.lower(k) if key == "q" then if box.Visible == false then box.Visible = true else box.Visible = false end end end