Aprender
Clase de motor
TextBox

*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.


Muestras de código
Palabra Secreta del TextBox
-- Coloca este código en un LocalScript dentro de un TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- blanco
local colorWrong = Color3.new(1, 0, 0) -- rojo
local colorCorrect = Color3.new(0, 1, 0) -- verde
-- Inicializa el estado del textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "¿Cuál es la palabra 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 = "ACCESO CONCEDIDO"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ACCESO DENEGADO"
textBox.BackgroundColor3 = colorWrong
end
else
-- El jugador dejó de editar sin presionar Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

Referencia API
Propiedades
ClearTextOnFocus
Leer paralelo
Capacidades: UI
TextBox.ClearTextOnFocus:boolean

ContentText
Solo lectura
No replicado
Leer paralelo
Capacidades: UI
TextBox.ContentText:string

CursorPosition
Leer paralelo
Capacidades: UI
TextBox.CursorPosition:number
Muestras de código
Selecciones de TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No hay selección")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('La selección es:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

Font
Oculto
No replicado
Leer paralelo
Capacidades: UI
TextBox.Font:Enum.Font

FontFace
Leer paralelo
Capacidades: UI
TextBox.FontFace:Font

FontSize
Obsoleto

LineHeight
Leer paralelo
Capacidades: UI
TextBox.LineHeight:number

MaxVisibleGraphemes
Leer paralelo
Capacidades: UI
TextBox.MaxVisibleGraphemes:number

MultiLine
Leer paralelo
Capacidades: UI
TextBox.MultiLine:boolean

OpenTypeFeatures
Leer paralelo
Capacidades: UI
TextBox.OpenTypeFeatures:string

OpenTypeFeaturesError
Solo lectura
No replicado
Leer paralelo
Capacidades: UI
TextBox.OpenTypeFeaturesError:string

PlaceholderColor3
Leer paralelo
Capacidades: UI
TextBox.PlaceholderColor3:Color3

PlaceholderText
Leer paralelo
Capacidades: UI
TextBox.PlaceholderText:string

RichText
Leer paralelo
Capacidades: UI
TextBox.RichText:boolean

SelectionStart
Leer paralelo
Capacidades: UI
TextBox.SelectionStart:number
Muestras de código
Selecciones de TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("No hay selección")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('La selección es:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput
Leer paralelo
Capacidades: UI
TextBox.ShowNativeInput:boolean

Text
Leer paralelo
Capacidades: UI
TextBox.Text:string

TextBounds
Solo lectura
No replicado
Leer paralelo
Capacidades: UI
TextBox.TextBounds:Vector2

TextColor
Obsoleto

TextColor3
Leer paralelo
Capacidades: UI
TextBox.TextColor3:Color3
Muestras de código
Detector de Vocales
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Comprobar si hay vocales
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Negro
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Rojo
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

TextDirection
Leer paralelo
Capacidades: UI
TextBox.TextDirection:Enum.TextDirection

TextEditable
Leer paralelo
Capacidades: UI
TextBox.TextEditable:boolean

TextFits
Solo lectura
No replicado
Leer paralelo
Capacidades: UI
TextBox.TextFits:boolean

TextScaled
Leer paralelo
Capacidades: UI
TextBox.TextScaled:boolean

TextSize
Leer paralelo
Capacidades: UI
TextBox.TextSize:number

TextStrokeColor3
Leer paralelo
Capacidades: UI
TextBox.TextStrokeColor3:Color3

TextStrokeTransparency
Leer paralelo
Capacidades: UI
TextBox.TextStrokeTransparency:number

TextTransparency
Leer paralelo
Capacidades: UI
TextBox.TextTransparency:number

TextTruncate
Leer paralelo
Capacidades: UI
TextBox.TextTruncate:Enum.TextTruncate

TextWrap
Obsoleto

TextWrapped
Leer paralelo
Capacidades: UI
TextBox.TextWrapped:boolean

TextXAlignment
Leer paralelo
Capacidades: UI
TextBox.TextXAlignment:Enum.TextXAlignment

TextYAlignment
Leer paralelo
Capacidades: UI
TextBox.TextYAlignment:Enum.TextYAlignment

Métodos
CaptureFocus
Capacidades: UI
TextBox:CaptureFocus():()
Devuelve
()
Muestras de código
Capturar el enfoque del 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
Capacidades: UI
TextBox:IsFocused():boolean
Devuelve

ReleaseFocus
Capacidades: UI
TextBox:ReleaseFocus(submitted:boolean):()
Parámetros
submitted:boolean
Valor predeterminado: false
Devuelve
()
Muestras de código
Liberar el enfoque del 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
Capacidades: UI
TextBox.Focused():RBXScriptSignal
Muestras de código
Enfoque del Cuadro de Texto
local textBox = script.Parent
textBox.Focused:Connect(function()
print("¡Enfocado!")
end)
textBox.FocusLost:Connect(function()
print("¡Enfoque perdido!")
end)

FocusLost
Capacidades: UI
TextBox.FocusLost(
enterPressed:boolean, inputThatCausedFocusLoss:InputObject
Parámetros
enterPressed:boolean
inputThatCausedFocusLoss:InputObject
Muestras de código
Enfoque del Cuadro de Texto
local textBox = script.Parent
textBox.Focused:Connect(function()
print("¡Enfocado!")
end)
textBox.FocusLost:Connect(function()
print("¡Enfoque perdido!")
end)
PerdidaDeFoco
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("El jugador presionó Enter")
else
print("El jugador presionó", 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("¡La atención se ha perdido porque se presionó enter!")
else
print("La atención se ha perdido sin que se presione enter")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
Capacidades: UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Roblox Corporation. Roblox, el logotipo de Roblox y "Powering Imagination" son algunas de nuestras marcas registradas y no registradas en los Estados Unidos y otros países.