Meer informatie
Engine-klasse
TextBox

*Deze inhoud is vertaald met behulp van AI (bèta) en kan fouten bevatten. Klik hier om deze pagina in het Engels te bekijken.


Codevoorbeelden
TextBox Geheime Woord
-- Plaats deze code in een LocalScript binnen een TextBox
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- wit
local colorWrong = Color3.new(1, 0, 0) -- rood
local colorCorrect = Color3.new(0, 1, 0) -- groen
-- Initialiseer de staat van de textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Wat is het geheime woord?"
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 = "TOEGANG TOEGESTAAN"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "TOEGANG GEWEIGERD"
textBox.BackgroundColor3 = colorWrong
end
else
-- De speler stopte met bewerken zonder op Enter te drukken
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

API-referentie
Eigenschappen
ClearTextOnFocus
Parallel lezen
Mogelijkheden: UI
TextBox.ClearTextOnFocus:boolean

ContentText
Alleen-lezen
Niet gerepliceerd
Parallel lezen
Mogelijkheden: UI
TextBox.ContentText:string

CursorPosition
Parallel lezen
Mogelijkheden: UI
TextBox.CursorPosition:number
Codevoorbeelden
TextBox Selecties
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Geen selectie")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('De selectie is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

Font
Verborgen
Niet gerepliceerd
Parallel lezen
Mogelijkheden: UI
TextBox.Font:Enum.Font

FontFace
Parallel lezen
Mogelijkheden: UI
TextBox.FontFace:Font

FontSize
Verouderd

LineHeight
Parallel lezen
Mogelijkheden: UI
TextBox.LineHeight:number

MaxVisibleGraphemes
Parallel lezen
Mogelijkheden: UI
TextBox.MaxVisibleGraphemes:number

MultiLine
Parallel lezen
Mogelijkheden: UI
TextBox.MultiLine:boolean

OpenTypeFeatures
Parallel lezen
Mogelijkheden: UI
TextBox.OpenTypeFeatures:string

OpenTypeFeaturesError
Alleen-lezen
Niet gerepliceerd
Parallel lezen
Mogelijkheden: UI
TextBox.OpenTypeFeaturesError:string

PlaceholderColor3
Parallel lezen
Mogelijkheden: UI
TextBox.PlaceholderColor3:Color3

PlaceholderText
Parallel lezen
Mogelijkheden: UI
TextBox.PlaceholderText:string

RichText
Parallel lezen
Mogelijkheden: UI
TextBox.RichText:boolean

SelectionStart
Parallel lezen
Mogelijkheden: UI
TextBox.SelectionStart:number
Codevoorbeelden
TextBox Selecties
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Geen selectie")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('De selectie is:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput
Parallel lezen
Mogelijkheden: UI
TextBox.ShowNativeInput:boolean

Text
Parallel lezen
Mogelijkheden: UI
TextBox.Text:string

TextBounds
Alleen-lezen
Niet gerepliceerd
Parallel lezen
Mogelijkheden: UI
TextBox.TextBounds:Vector2

TextColor
Verouderd

TextColor3
Parallel lezen
Mogelijkheden: UI
TextBox.TextColor3:Color3
Codevoorbeelden
Klinker Detector
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Controleer op klinkers
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Zwart
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Rood
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

TextDirection
Parallel lezen
Mogelijkheden: UI
TextBox.TextDirection:Enum.TextDirection

TextEditable
Parallel lezen
Mogelijkheden: UI
TextBox.TextEditable:boolean

TextFits
Alleen-lezen
Niet gerepliceerd
Parallel lezen
Mogelijkheden: UI
TextBox.TextFits:boolean

TextScaled
Parallel lezen
Mogelijkheden: UI
TextBox.TextScaled:boolean

TextSize
Parallel lezen
Mogelijkheden: UI
TextBox.TextSize:number

TextStrokeColor3
Parallel lezen
Mogelijkheden: UI
TextBox.TextStrokeColor3:Color3

TextStrokeTransparency
Parallel lezen
Mogelijkheden: UI
TextBox.TextStrokeTransparency:number

TextTransparency
Parallel lezen
Mogelijkheden: UI
TextBox.TextTransparency:number

TextTruncate
Parallel lezen
Mogelijkheden: UI
TextBox.TextTruncate:Enum.TextTruncate

TextWrap
Verouderd

TextWrapped
Parallel lezen
Mogelijkheden: UI
TextBox.TextWrapped:boolean

TextXAlignment
Parallel lezen
Mogelijkheden: UI
TextBox.TextXAlignment:Enum.TextXAlignment

TextYAlignment
Parallel lezen
Mogelijkheden: UI
TextBox.TextYAlignment:Enum.TextYAlignment

Methoden
CaptureFocus
Mogelijkheden: UI
TextBox:CaptureFocus():()
Teruggaves
()
Codevoorbeelden
Vang Tekstvak Focus
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
Mogelijkheden: UI
TextBox:IsFocused():boolean
Teruggaves

ReleaseFocus
Mogelijkheden: UI
TextBox:ReleaseFocus(submitted:boolean):()
Parameters
submitted:boolean
Standaardwaarde: false
Teruggaves
()
Codevoorbeelden
Focus van TextBox Vrijgeven
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)

Evenementen
Focused
Mogelijkheden: UI
TextBox.Focused():RBXScriptSignal
Codevoorbeelden
TextBox Focus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Gefocust!")
end)
textBox.FocusLost:Connect(function()
print("Focus verloren!")
end)

FocusLost
Mogelijkheden: UI
TextBox.FocusLost(
enterPressed:boolean, inputThatCausedFocusLoss:InputObject
Parameters
enterPressed:boolean
inputThatCausedFocusLoss:InputObject
Codevoorbeelden
TextBox Focus
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Gefocust!")
end)
textBox.FocusLost:Connect(function()
print("Focus verloren!")
end)
FocusVerlies
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Speler drukte op Enter")
else
print("Speler drukte op", 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("Focus is verloren omdat de enter-toets is ingedrukt!")
else
print("Focus is verloren zonder dat de enter-toets is ingedrukt")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
Mogelijkheden: UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Roblox Corporation. Roblox, het Roblox-logo en Powering Imagination behoren tot onze geregistreerde en niet-geregistreerde handelsmerken in de VS en andere landen.