Aprenda
Classe do mecanismo
TextBox

*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.


Amostras de código
Caixa de Texto Senha Secreta
-- Coloque este código em um LocalScript dentro de uma Caixa de Texto
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- branco
local colorWrong = Color3.new(1, 0, 0) -- vermelho
local colorCorrect = Color3.new(0, 1, 0) -- verde
-- Inicialize o estado da textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Qual é a palavra secreta?"
textBox.BackgroundColor3 = colorNormal
local function onFocused()
textBox.BackgroundColor3 = colorNormal
end
local function onFocusLost(enterPressed, _inputObject)
if enterPressed then
local guess = textBox.Text
if guess == secretWord then
textBox.Text = "ACESSO CONCEDIDO"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACESSO NEGADO"
textBox.BackgroundColor3 = colorWrong
end
else
-- O jogador parou de editar sem pressionar Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

Referência API
Propriedades
ClearTextOnFocus
Ler Parallel
Recursos: UI
TextBox.ClearTextOnFocus:boolean

ContentText
Somente leitura
Não replicado
Ler Parallel
Recursos: UI
TextBox.ContentText:string

CursorPosition
Ler Parallel
Recursos: UI
TextBox.CursorPosition:number
Amostras de código
Seleções de TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Sem seleção")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('A seleção é:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

Font
Oculto
Não replicado
Ler Parallel
Recursos: UI
TextBox.Font:Enum.Font

FontFace
Ler Parallel
Recursos: UI
TextBox.FontFace:Font

FontSize
Obsoleto

LineHeight
Ler Parallel
Recursos: UI
TextBox.LineHeight:number

MaxVisibleGraphemes
Ler Parallel
Recursos: UI
TextBox.MaxVisibleGraphemes:number

MultiLine
Ler Parallel
Recursos: UI
TextBox.MultiLine:boolean

OpenTypeFeatures
Ler Parallel
Recursos: UI
TextBox.OpenTypeFeatures:string

OpenTypeFeaturesError
Somente leitura
Não replicado
Ler Parallel
Recursos: UI
TextBox.OpenTypeFeaturesError:string

PlaceholderColor3
Ler Parallel
Recursos: UI
TextBox.PlaceholderColor3:Color3

PlaceholderText
Ler Parallel
Recursos: UI
TextBox.PlaceholderText:string

RichText
Ler Parallel
Recursos: UI
TextBox.RichText:boolean

SelectionStart
Ler Parallel
Recursos: UI
TextBox.SelectionStart:number
Amostras de código
Seleções de TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Sem seleção")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('A seleção é:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput
Ler Parallel
Recursos: UI
TextBox.ShowNativeInput:boolean

Text
Ler Parallel
Recursos: UI
TextBox.Text:string

TextBounds
Somente leitura
Não replicado
Ler Parallel
Recursos: UI
TextBox.TextBounds:Vector2

TextColor
Obsoleto

TextColor3
Ler Parallel
Recursos: UI
TextBox.TextColor3:Color3
Amostras de código
Detector de Vogais
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Verifique se há vogais
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Preto
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Vermelho
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

TextDirection
Ler Parallel
Recursos: UI
TextBox.TextDirection:Enum.TextDirection

TextEditable
Ler Parallel
Recursos: UI
TextBox.TextEditable:boolean

TextFits
Somente leitura
Não replicado
Ler Parallel
Recursos: UI
TextBox.TextFits:boolean

TextScaled
Ler Parallel
Recursos: UI
TextBox.TextScaled:boolean

TextSize
Ler Parallel
Recursos: UI
TextBox.TextSize:number

TextStrokeColor3
Ler Parallel
Recursos: UI
TextBox.TextStrokeColor3:Color3

TextStrokeTransparency
Ler Parallel
Recursos: UI
TextBox.TextStrokeTransparency:number

TextTransparency
Ler Parallel
Recursos: UI
TextBox.TextTransparency:number

TextTruncate
Ler Parallel
Recursos: UI
TextBox.TextTruncate:Enum.TextTruncate

TextWrap
Obsoleto

TextWrapped
Ler Parallel
Recursos: UI
TextBox.TextWrapped:boolean

TextXAlignment
Ler Parallel
Recursos: UI
TextBox.TextXAlignment:Enum.TextXAlignment

TextYAlignment
Ler Parallel
Recursos: UI
TextBox.TextYAlignment:Enum.TextYAlignment

Métodos
CaptureFocus
Recursos: UI
TextBox:CaptureFocus():()
Devolução
()
Amostras de código
Capturar Foco do TextBox
local UserInputService = game:GetService("UserInputService")
local textBox = script.Parent
local input = UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.Q then
textBox:CaptureFocus()
end
end)

IsFocused
Recursos: UI
TextBox:IsFocused():boolean
Devolução

ReleaseFocus
Recursos: UI
TextBox:ReleaseFocus(submitted:boolean):()
Parâmetros
submitted:boolean
Valor Padrão: false
Devolução
()
Amostras de código
Liberar o Foco do TextBox
local UserInputService = game:GetService("UserInputService")
local textBox = script.Parent
local input = UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.Escape and textBox.IsFocused then
textBox:ReleaseFocus()
end
end)

Eventos
Focused
Recursos: UI
TextBox.Focused():RBXScriptSignal
Amostras de código
Foco da Caixa de Texto
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Focado!")
end)
textBox.FocusLost:Connect(function()
print("Foco perdido!")
end)

FocusLost
Recursos: UI
TextBox.FocusLost(
enterPressed:boolean, inputThatCausedFocusLoss:InputObject
Parâmetros
enterPressed:boolean
inputThatCausedFocusLoss:InputObject
Amostras de código
Foco da Caixa de Texto
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Focado!")
end)
textBox.FocusLost:Connect(function()
print("Foco perdido!")
end)
PerdaDeFoco
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Jogador pressionou Enter")
else
print("Jogador pressionou", inputThatCausedFocusLost.KeyCode)
end
end
textBox.FocusLost:Connect(onFocusLost)
TextBox.FocusLost1
local gui = script.Parent
local textBox = gui.TextBox
local function focusLost(enterPressed)
if enterPressed then
print("O foco foi perdido porque a tecla enter foi pressionada!")
else
print("O foco foi perdido sem a tecla enter ser pressionada")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
Recursos: UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Roblox Corporation, Roblox, o logotipo Roblox e Powering Imagination estão entre nossas marcas registradas e não registradas nos EUA e em outros países.