FocusLost
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/TextBoxFocused
and /UserInputService/TextBoxFocusReleased
for similar functions that rely on the UserInputService service.
This event will only fire when used in a /LocalScript
.
Parameters
Name | Type | Default | Description |
---|---|---|---|
|
A boolean indicating whether the client pressed Enter to lose focus (true) or not (false). |
||
|
An |
Code Samples
TextBox.FocusLost1
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.
FocusLost
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.
or - “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’.