How to wait until a button is pressed

I’m sure this exists somewhere, but I have searched the forums and google as much as I can and couldn’t find a solution.

Basically, I’m just trying to, when a button is pressed/clicked, wait until any keyboard key is pressed and then get what button that was. I also want it to stop waiting if the escape key is pressed or the mouse is clicked off the button.

There’s more in the code then just this, but this should just be the only important part. One thing to note is it reaches “Here”, but not “Here2.” (it’s a local script, too):

script.Parent.SettingsFrame.InnerFrame.Run.MouseButton1Click:Connect(function()
		script.Parent.SettingsFrame.InnerFrame.Run.UIStroke.UIG.Enabled = true
		print("Here")
		Input.InputBegan:Wait(function(key)
			print("Here2")
			print(key)
			script.Parent.SettingsFrame.InnerFrame.Run.UIStroke.UIG.Enabled = false
		end)
		
	end)
1 Like

Just have whatever needs to be executed after the input, after the inputBegan:Wait()

local key = Input.InputBegan:Wait()

script.Parent.SettingsFrame.InnerFrame.Run.UIStroke.UIG.Enabled = false
1 Like