This function returns the
TextBox the client is currently focused on. A TextBox can be manually selected by the user, or selection can be forced using the
TextBox/CaptureFocus function. If no TextBox is selected, this function will return nil.
UserInputService is client-side only, this function can only be used in a
Ignore User Input When a TextBox Is Focused
This example demonstrates how to ignore user input when any
TextBox is focused. When a player is not focusing on any TextBox, pressing the jumpKey (
Enum/KeyCode|J Key) change’s their humanoid’s
Enum/HumanoidStateType|state to Jumping using the
Humanoid/ChangeState function to make their character jump.
When the player is focusing on any TextBox, the player will not jump. The example checks if any TextBox is focused by checking if the
UserInputService/GetFocusedTextbox function returns
nil instead of a TextBox instance.
This connects to the
Humanoid/StateChanged event to determine when the player is jumping and prevent the player from using the jumpKey to jump while already jumping.