How can I open this GUI with a Key from the Keyboard?

Hello,

I’m trying to open a Frame in a GUI by pressing “q”, what am I doing wrong in the big code below? (DW, most of it is Constants.)

local currentPage = full.CurrentPage
local pagesList = full.Pages
local topBar = full.Topbar

local divider1 = full.dividers.Frame1
local divider2 = full.dividers.Frame2


local mouse = game.Players.LocalPlayer:GetMouse()
local gui = script.Parent

mouse.KeyDown:connect(function(key)
	if key ==  "q" then


		full:TweenSize(
			UDim2.new(0, 618,0, 395),
			Enum.EasingDirection.In,  
			Enum.EasingStyle.Sine,     
			2,                         
			true	                    
		)

		wait(2)

		close.Visible = true
		pagesList.Visible = true
		divider1.Visible = true
		divider2.Visible = true
	end
end)

Thanks, AridOats.

4 Likes

Use UserInputService | Documentation - Roblox Creator Hub, specifically the UserInputService | Documentation - Roblox Creator Hub event for this instead of using mouse.KeyDown.

1 Like

Adding on to @Aerosphia, you may also want to consider using the ContextActionService | Documentation - Roblox Creator Hub. While it is a bit harder to figure out at first, players will likely find it very useful in preventing unwanted menus from opening while chatting!

ok, thankyou!

So, what would I change to what, exactly? Sorry, I’m not… fully sure…!

[EDIT] actually, I’ve figured it out now, sorry, thanks again!

As an example. (this isn’t tested, correct me if I’m wrong)

userInput.InputBegan:Connect(function(input,gameProcessed)
    if gameProccessed then -- Prevents this from running when typing in chat
        if input.KeyCode == Enum.KeyCode.Q then

        end 
    end
end)
8 Likes

hey, so gameProccessed is Undefined, what is it that I can do to Define this?

You’re spelling it wrong. If you’re spelling it as “gameProccessed”, it should be changed to gameProcessed.

But first you have to do

local UserInputService = game:GetService(“UserInputService”)

local Frame = game.StarterGui.ScreenGui.Frame

UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
if input.KeyCode == Enum.KeyCode.Q then
Frame.Visible = true
end

2 Likes

end
end)

  • you forgot end)

Oh sorry, sometimes it’s hard to write code into Non-IDE’s