How to wait until player press key on their keyboard?

Hi
Today I have to try to script the loading screen when it success loading then I want to wait until player press key on their keyboard?

local UserInputService = game:GetService("UserInputService")
repeat wait() until script.Parent.Frame.MouseButton1Click:Wait() or UserInputService.InputBegan:Wait()
print("End of the loop")

but when I try to use it when I press any key it doesn’t work at all

Thank you and sorry for bad English.

1 Like

Instead of waiting you should actually do the code when someone touched key for eg

script.Parent.MouseButton1Click:Connect(function()
--script here
end)

but i want to do like press on screen or press any key

Tell them to press a key once they do just do the code

ok i will try it (So this is 30 characters)

It looks like you already have the solution in your code, just write

game:GetService("UserInputService").InputBegan:Wait()

and the script will wait until the user makes an input (this includes tapping, keys, mouse clicks, button presses on a controller, etc)

10 Likes

It’s work now!
Thank for the answer
to @prepsure and @megatank58

Maybe because I put

script.Parent.Frame.MouseButton1Click:Wait() 

so my old script doesn’t work

1 Like

Do you mind telling me where you put the script?? I want to create a similar GUI for my game.

I am making a reload script and I am trying to make it where the gun doesn’t play the reload sound when someone presses ‘R’ and the gun isn’t equipped. How do I do that?