Codectionary / Developer documentation / Luau

TextBox input

Read text typed by a player and respond when editing ends.

Why use TextBox?

TextBox accepts user-entered text. FocusLost fires when editing ends and reports whether Enter was pressed; any value sent to a server must be validated there.

Try it in Roblox Studio

Create StarterGui > PracticeGui (ScreenGui) > NameBox (TextBox) and add this LocalScript inside NameBox. Type a value in a Studio client.

Syntax

textBox.FocusLost:Connect(function(enterPressed) ... end)

Examples

TextBox input

Show the entered text in Output after Enter is pressed.

local textBox = script.Parent
assert(textBox:IsA("TextBox"))
textBox.PlaceholderText = "Enter a display name"
textBox.FocusLost:Connect(function(enterPressed)
    if enterPressed then
        print("Entered:", textBox.Text)
    end
end)
  1. PlaceholderText gives a hint before the user types.
  2. FocusLost runs when the box stops receiving input; enterPressed distinguishes an Enter submission from another loss of focus.
  3. Text is untrusted user input. The example only prints it locally and does not save or publish it.

Best practices

  • Validate length and allowed content on the server before saving input.
  • Explain what an input field is for with visible surrounding UI.

Runtime & versions

Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Luau documentation

Specifications & further reading