How to make the 'Press any key button to start' work?

Hello! I am here asking for some assistance (like you’ve read in the title) on a system I have been working on (image attached).
uno

Once you press any key of your choice, I want this UI to fade out and a new UI fades in, if you have any ideas please feel free to send a message, otherwise have a nice day. :smile:

I believe this?

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(key)
    if key.UserInputType == Enum.UserInputType.Keyboard then
        --pressed key
    end
end)
1 Like

Can you elaborate why it is this?

UserInputService.InputBegan is an event that fire whenever the user makes any kind of input (mouse, keyboard, tap, etc)

In @Kaid3n22 code snippet, he uses the event and detects whether the input type is Keyboard.

So you’d put the code to fade the UI inside the if statement.

3 Likes

The code kaiden just posted basically detects if the user has pressed a key on their keyboard.

You would also have to check GameProcessedEvent if you dont want it to start when you are chatting.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(key,gpe)
    if key.UserInputType == Enum.UserInputType.Keyboard and not processed then
        --pressed key
    end
end)

How would I make it that it processes any input that isn’t mouse movement rather than just keyboard

I would say add a hidden text/image button and check when it’s clicked do the same thing as with the UserInputService. (size of the entire gui)

This did not work, Press any key as seen here: I was pressing any key on my keyboard and it did not work

Maybe its this?

local UIS = game:GetService("UserInputService")
local keys = Enum.Keycode:GetEnumItems()

local inputConn

inputConn = UIS.InputBegan:Connect(function(input, typing)
   if not typing then -- You can change this.
       if table.find(keys, input.KeyCode) then
          -- Stuff
          inputConn:Disconnect() -- Makes it so this event stops firing.
       end
   end
end)

you would check for any input. I would also add it to a connection and disconnect it later so it doesn’t keep firing

local UIS = game:GetService("UserInputService")
local connection = nil

connection = UIS.InputBegan:Connect(function(input, gpe)
    if gpe then return end
    --- do stuff
    connection:Disconnect()
    connection = nil
end)

He tried that once and didn’t work, also, can i take the “connection” thing and edit it into my post?

why tho? it should work perfectly

well some guy did it first and he answered that it didn’t work

that one checks only for keyboard which should work too but not for mouse or gamepad. i believe op has something wrong in their code

What? it should detect gamepad aswell, check Enum.KeyCode
or i can just detect it using userinputtype

I’m not talking about yours. yours should work perfectly as well except it will keep firing.
edit: i see you just edited it. so it should do the exact same thing as mine

Yep it works (mine too), just tested both of our codes it really seems like op has smth wrong in code

1 Like


This is what I got from using your code.

I believe DioGotHeaven made a typo, it is supposed to be “KeyCode”, not “Keycode”