For thread safety, this property is not safe to read in an unsynchronized thread.
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/TextBoxFocusReleased for similar functions that rely on the UserInputService service.
This event will only fire when used in a
A boolean indicating whether the client pressed Enter to lose focus (true) or not (false).
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.
script.Parent.FocusLost:Connect(function(enterPressed) if enterPressed then print("Focus was lost because enter was pressed!") end end)
This example works when placed in a
/LocalScript that is the child of a TextBox. When the TextBox loses focus, the example prints either:
- “Player pressed Enter” - if the TextBox lost focus because the player pressed the Enter key.
- “Player pressed InputObject.KeyCode” - where “KeyCode” is the
/InputObjectKeyCode 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") else print("Player pressed", inputThatCausedFocusLost.KeyCode) end end)