Pelajari
Kelas Engine
TextBox

*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.


Contoh Kode
Kotak Teks Kata Sandi
-- Tempatkan kode ini dalam LocalScript di dalam Kotak Teks
local textBox = script.Parent
local secretWord = "roblox"
local colorNormal = Color3.new(1, 1, 1) -- putih
local colorWrong = Color3.new(1, 0, 0) -- merah
local colorCorrect = Color3.new(0, 1, 0) -- hijau
-- Inisialisasi keadaan textBox
textBox.ClearTextOnFocus = true
textBox.Text = ""
textBox.Font = Enum.Font.Code
textBox.PlaceholderText = "Apa kata sandi rahasianya?"
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 = "AKSES DIIZINKAN"
textBox.BackgroundColor3 = colorCorrect
else
textBox.Text = "AKSES DITOLAK"
textBox.BackgroundColor3 = colorWrong
end
else
-- Pemain berhenti mengedit tanpa menekan Enter
textBox.Text = ""
textBox.BackgroundColor3 = colorNormal
end
end
textBox.FocusLost:Connect(onFocusLost)
textBox.Focused:Connect(onFocused)

Referensi API
Properti
ClearTextOnFocus
Baca Paralel
Kemampuan: UI
TextBox.ClearTextOnFocus:boolean

ContentText
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: UI
TextBox.ContentText:string

CursorPosition
Baca Paralel
Kemampuan: UI
TextBox.CursorPosition:number
Contoh Kode
Pilihan TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Tidak ada pilihan")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('Pilihan adalah:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

Font
Tersembunyi
Tidak Direplikasi
Baca Paralel
Kemampuan: UI
TextBox.Font:Enum.Font

FontFace
Baca Paralel
Kemampuan: UI
TextBox.FontFace:Font

FontSize
Tidak digunakan lagi

LineHeight
Baca Paralel
Kemampuan: UI
TextBox.LineHeight:number

MaxVisibleGraphemes
Baca Paralel
Kemampuan: UI
TextBox.MaxVisibleGraphemes:number

MultiLine
Baca Paralel
Kemampuan: UI
TextBox.MultiLine:boolean

OpenTypeFeatures
Baca Paralel
Kemampuan: UI
TextBox.OpenTypeFeatures:string

OpenTypeFeaturesError
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: UI
TextBox.OpenTypeFeaturesError:string

PlaceholderColor3
Baca Paralel
Kemampuan: UI
TextBox.PlaceholderColor3:Color3

PlaceholderText
Baca Paralel
Kemampuan: UI
TextBox.PlaceholderText:string

RichText
Baca Paralel
Kemampuan: UI
TextBox.RichText:boolean

SelectionStart
Baca Paralel
Kemampuan: UI
TextBox.SelectionStart:number
Contoh Kode
Pilihan TextBox
local textBox = script.Parent
local function showSelection()
if textBox.CursorPosition == -1 or textBox.SelectionStart == -1 then
print("Tidak ada pilihan")
else
local selectedText = string.sub(
textBox.Text,
math.min(textBox.CursorPosition, textBox.SelectionStart),
math.max(textBox.CursorPosition, textBox.SelectionStart)
)
print('Pilihan adalah:"', selectedText, '"')
end
end
textBox:GetPropertyChangedSignal("CursorPosition"):Connect(showSelection)
textBox:GetPropertyChangedSignal("SelectionStart"):Connect(showSelection)

ShowNativeInput
Baca Paralel
Kemampuan: UI
TextBox.ShowNativeInput:boolean

Text
Baca Paralel
Kemampuan: UI
TextBox.Text:string

TextBounds
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: UI
TextBox.TextBounds:Vector2

TextColor
Tidak digunakan lagi

TextColor3
Baca Paralel
Kemampuan: UI
TextBox.TextColor3:Color3
Contoh Kode
Detektor Vokal
local textBox = script.Parent
local function hasVowels(str)
return str:lower():find("[aeiou]")
end
local function onTextChanged()
local text = textBox.Text
-- Periksa vokal
if hasVowels(text) then
textBox.TextColor3 = Color3.new(0, 0, 0) -- Hitam
else
textBox.TextColor3 = Color3.new(1, 0, 0) -- Merah
end
end
textBox:GetPropertyChangedSignal("Text"):Connect(onTextChanged)

TextDirection
Baca Paralel
Kemampuan: UI
TextBox.TextDirection:Enum.TextDirection

TextEditable
Baca Paralel
Kemampuan: UI
TextBox.TextEditable:boolean

TextFits
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: UI
TextBox.TextFits:boolean

TextScaled
Baca Paralel
Kemampuan: UI
TextBox.TextScaled:boolean

TextSize
Baca Paralel
Kemampuan: UI
TextBox.TextSize:number

TextStrokeColor3
Baca Paralel
Kemampuan: UI
TextBox.TextStrokeColor3:Color3

TextStrokeTransparency
Baca Paralel
Kemampuan: UI
TextBox.TextStrokeTransparency:number

TextTransparency
Baca Paralel
Kemampuan: UI
TextBox.TextTransparency:number

TextTruncate
Baca Paralel
Kemampuan: UI
TextBox.TextTruncate:Enum.TextTruncate

TextWrap
Tidak digunakan lagi

TextWrapped
Baca Paralel
Kemampuan: UI
TextBox.TextWrapped:boolean

TextXAlignment
Baca Paralel
Kemampuan: UI
TextBox.TextXAlignment:Enum.TextXAlignment

TextYAlignment
Baca Paralel
Kemampuan: UI
TextBox.TextYAlignment:Enum.TextYAlignment

Metode
CaptureFocus
Kemampuan: UI
TextBox:CaptureFocus():()
Memberikan nilai
()
Contoh Kode
Mengambil Fokus 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
Kemampuan: UI
TextBox:IsFocused():boolean
Memberikan nilai

ReleaseFocus
Kemampuan: UI
TextBox:ReleaseFocus(submitted:boolean):()
Parameter
submitted:boolean
Nilai Default: false
Memberikan nilai
()
Contoh Kode
Lepaskan Fokus 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)

Acara
Focused
Kemampuan: UI
TextBox.Focused():RBXScriptSignal
Contoh Kode
Fokus TextBox
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Fokus!")
end)
textBox.FocusLost:Connect(function()
print("Fokus hilang!")
end)

FocusLost
Kemampuan: UI
TextBox.FocusLost(
enterPressed:boolean, inputThatCausedFocusLoss:InputObject
Parameter
enterPressed:boolean
inputThatCausedFocusLoss:InputObject
Contoh Kode
Fokus TextBox
local textBox = script.Parent
textBox.Focused:Connect(function()
print("Fokus!")
end)
textBox.FocusLost:Connect(function()
print("Fokus hilang!")
end)
Fokus Hilang
local textBox = script.Parent
local function onFocusLost(enterPressed, inputThatCausedFocusLost)
if enterPressed then
print("Pemain menekan Enter")
else
print("Pemain menekan", 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("Fokus hilang karena tombol enter ditekan!")
else
print("Fokus hilang tanpa tombol enter ditekan")
end
end
textBox.FocusLost:Connect(focusLost)

ReturnPressedFromOnScreenKeyboard
Kemampuan: UI
TextBox.ReturnPressedFromOnScreenKeyboard():RBXScriptSignal

©2026 Roblox Corporation. Roblox, logo Roblox, dan Powering Imagination termasuk dalam merek dagang kami yang terdaftar dan tidak terdaftar di AS dan negara lainnya.