Collapse Sidebar


The FocusLost event fires when the client lets their focus off the TextBox - typically when a client clicks/taps on a TextBox to begin text entry. This also fires if a TextBox forces focus on the user.

It can be used alongside TextBox.Focus to track when a TextBox gains and loses focus.

See also the /UserInputService/TextBoxFocused and /UserInputService/TextBoxFocusReleased for similar functions that rely on the UserInputService service.

This event will only fire when used in a /LocalScript.


Name Type Default Description

A boolean indicating whether the client pressed Enter to lose focus (true) or not (false).

An InputObject instance indicating the type of input that caused the TextBox to lose focus.

Code Samples


The example shown below will print “Focus was lost because enter was pressed!” whenever the TextBox loses focus as a result of the enter key being pressed.

    if enterPressed then
        print("Focus was lost because enter was pressed!")


This example works when placed in a /LocalScript that is the child of a TextBox. When the TextBox loses focus, the example prints either:

  1. “Player pressed Enter” - if the TextBox lost focus because the player pressed the Enter key.
  2. “Player pressed InputObject.KeyCode” - where “KeyCode” is the /InputObject KeyCode property of the input that caused the TextBox to lose focus. For example, pressing the Escape (esc) key to exit TextBox focus returns an InputObject instance with the KeyCode ‘InputObject.Escape’.
TextBox.FocusLost:Connect(function(enterPressed, inputThatCausedFocusLost)
	if enterPressed then
		print("Player pressed Enter")
		print("Player pressed", inputThatCausedFocusLost.KeyCode)