Hi, I want to make a script with them I can open / close a gui with the key q. That´s what I have but I doesn´t work.
-- Variables --
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
GUI = game.StarterGui.Handbook.StartMenue
Box = GUI.GameFrame
Open = false
-- Function --
´function PressQ(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
Mouse.Keydown:conncect(PressQ)
Instead of using the Player’s mouse, you’re going to use UserInputService, like MCAndRobloxUnited stated.
local UserInputService = game:GetService('UserInputService') local key = 'Enum.KeyCode.Q' -- Use local when Global variables aren't needed -- Use WaitForChild() on children local Handbook = game.StarterGui:WaitForChild("Handbook") local StartMenue = Handbook:WaitForChild("StartMenue") local GameFrame = StartMenue:WaitForChild("GameFrame") UserInputService.InputBegan:Connect(function(input) -- Turn the KeyCode Enum into a String -- Match it to our key if tostring(input.KeyCode) == key then -- You can substitute the if statements with the reverse of visible GameFrame.Visible = not GameFrame.Visible end end)