Lernen
Engine-Klasse
TextBox

*Dieser Inhalt wurde mit KI (Beta) übersetzt und kann Fehler enthalten. Um diese Seite auf Englisch zu sehen, klicke hier.


Code-Beispiele
TextBox geheimes Wort
-- Platziere diesen Code in einem LocalScript innerhalb einer TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- weiß
local colorWrong = Color3.new(1, 0, 0) -- rot
local colorCorrect = Color3.new(0, 1, 0) -- grün
-- Initialisiere den Zustand der textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Was ist das geheime Wort?"
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 = "ZUGANG ERTEILT"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "ZUGANG VERWEIGERT"
textBox.BackgroundColor3 = colorWrong
end
else
-- Der Spieler hat das Bearbeiten ohne Drücken von Enter beendet
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

API-Referenz
Eigenschaften
ClearTextOnFocus
Parallel lesen
Funktionen: UI
TextBox.ClearTextOnFocus:boolean

ContentText
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: UI
TextBox.ContentText:string

CursorPosition
Parallel lesen
Funktionen: UI
TextBox.CursorPosition:number
Code-Beispiele
TextBox-Auswahlen
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Keine Auswahl")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('Die Auswahl ist:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

Font
Verborgen
Nicht repliziert
Parallel lesen
Funktionen: UI
TextBox.Font:Enum.Font

FontFace
Parallel lesen
Funktionen: UI
TextBox.FontFace:Font

FontSize
Veraltet

LineHeight
Parallel lesen
Funktionen: UI
TextBox.LineHeight:number

MaxVisibleGraphemes
Parallel lesen
Funktionen: UI
TextBox.MaxVisibleGraphemes:number

MultiLine
Parallel lesen
Funktionen: UI
TextBox.MultiLine:boolean

OpenTypeFeatures
Parallel lesen
Funktionen: UI
TextBox.OpenTypeFeatures:string

OpenTypeFeaturesError
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: UI
TextBox.OpenTypeFeaturesError:string

PlaceholderColor3
Parallel lesen
Funktionen: UI
TextBox.PlaceholderColor3:Color3

PlaceholderText
Parallel lesen
Funktionen: UI
TextBox.PlaceholderText:string

RichText
Parallel lesen
Funktionen: UI
TextBox.RichText:boolean

SelectionStart
Parallel lesen
Funktionen: UI
TextBox.SelectionStart:number
Code-Beispiele
TextBox-Auswahlen
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Keine Auswahl")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('Die Auswahl ist:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput
Parallel lesen
Funktionen: UI
TextBox.ShowNativeInput:boolean

Text
Parallel lesen
Funktionen: UI
TextBox.Text:string

TextBounds
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: UI
TextBox.TextBounds:Vector2

TextColor
Veraltet

TextColor3
Parallel lesen
Funktionen: UI
TextBox.TextColor3:Color3
Code-Beispiele
Vokal Detector
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Überprüfen Sie auf Vokale
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Schwarz
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Rot
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

TextDirection
Parallel lesen
Funktionen: UI
TextBox.TextDirection:Enum.TextDirection

TextEditable
Parallel lesen
Funktionen: UI
TextBox.TextEditable:boolean

TextFits
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: UI
TextBox.TextFits:boolean

TextScaled
Parallel lesen
Funktionen: UI
TextBox.TextScaled:boolean

TextSize
Parallel lesen
Funktionen: UI
TextBox.TextSize:number

TextStrokeColor3
Parallel lesen
Funktionen: UI
TextBox.TextStrokeColor3:Color3

TextStrokeTransparency
Parallel lesen
Funktionen: UI
TextBox.TextStrokeTransparency:number

TextTransparency
Parallel lesen
Funktionen: UI
TextBox.TextTransparency:number

TextTruncate
Parallel lesen
Funktionen: UI
TextBox.TextTruncate:Enum.TextTruncate

TextWrap
Veraltet

TextWrapped
Parallel lesen
Funktionen: UI
TextBox.TextWrapped:boolean

TextXAlignment
Parallel lesen
Funktionen: UI
TextBox.TextXAlignment:Enum.TextXAlignment

TextYAlignment
Parallel lesen
Funktionen: UI
TextBox.TextYAlignment:Enum.TextYAlignment

Methoden
CaptureFocus
Funktionen: UI
TextBox:CaptureFocus():()
Rückgaben
()
Code-Beispiele
Fokus auf TextBox erfassen
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
Funktionen: UI
TextBox:IsFocused():boolean
Rückgaben

ReleaseFocus
Funktionen: UI
TextBox:ReleaseFocus(submitted:boolean):()
Parameter
submitted:boolean
Standardwert: false
Rückgaben
()
Code-Beispiele
Fokus des Textfeldes freigeben
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)

Events
Focused
Funktionen: UI
TextBox.Focused():RBXScriptSignal
Code-Beispiele
TextBox Fokus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Fokussiert!")
end)
textBox.FocusLost:Connect(function()
print("Fokus verloren!")
end)

FocusLost
Funktionen: UI
TextBox.FocusLost(
enterPressed:boolean, inputThatCausedFocusLoss:InputObject
Parameter
enterPressed:boolean
inputThatCausedFocusLoss:InputObject
Code-Beispiele
TextBox Fokus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Fokussiert!")
end)
textBox.FocusLost:Connect(function()
print("Fokus verloren!")
end)
FokusVerloren
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Spieler hat Eingabetaste gedrückt")
else
print("Spieler hat gedrückt", 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("Der Fokus ging verloren, weil Enter gedrückt wurde!")
else
print("Der Fokus ging verloren, ohne dass Enter gedrückt wurde")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
Funktionen: UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Roblox Corporation. Roblox, das Roblox-Logo und "Powering Imagination" gehören zu unseren eingetragenen und nicht eingetragenen Markenzeichen in den USA und anderen Ländern.