学ぶ
エンジンクラス
TextLabel

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


コードサンプル
ゲームの状態テキスト
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- ReplicatedStorageに"GameState"というStringValueを置いてください
local vGameState = ReplicatedStorage:WaitForChild("GameState")
-- このコードをTextLabelに置いてください
local textLabel = script.Parent
-- TextColor3で使用するいくつかの色
local colorNormal = Color3.new(0, 0, 0) -- 黒
local colorCountdown = Color3.new(1, 0.5, 0) -- オレンジ
local colorRound = Color3.new(0.25, 0.25, 1) -- 青
-- ゲームの状態が変更されるたびにTextLabelを更新するためにこの関数を実行します。
local function update()
-- テキストを更新
textLabel.Text = "状態: " .. vGameState.Value
-- 現在のゲームの状態に基づいてテキストの色を設定
if vGameState.Value == "Countdown" then
textLabel.TextColor3 = colorCountdown
elseif vGameState.Value == "Round" then
textLabel.TextColor3 = colorRound
else
textLabel.TextColor3 = colorNormal
end
end
-- パターン: 開始時とvGameStateが変更されるたびに一度更新
-- 常に最新のGameStateが表示されるはずです。
update()
vGameState.Changed:Connect(update)

APIリファレンス
プロパティ
ContentText
読み取り専用
複製されていません
並列読み取り
機能: UI
TextLabel.ContentText:string

Font
非表示
複製されていません
並列読み取り
機能: UI
TextLabel.Font:Enum.Font
コードサンプル
すべてのフォントを表示
local frame = script.Parent
-- 各フォントを表示するTextLabelを作成
for _, font in pairs(Enum.Font:GetEnumItems()) do
local textLabel = Instance.new("TextLabel")
textLabel.Name = font.Name
-- テキストプロパティを設定
textLabel.Text = font.Name
textLabel.Font = font
-- 一部のレンダリングプロパティ
textLabel.TextSize = 24
textLabel.TextXAlignment = Enum.TextXAlignment.Left
-- テキストの高さに等しくフレームのサイズを設定
textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextSize)
-- 親フレームに追加
textLabel.Parent = frame
end
-- フレームをリストでレイアウトする(すでにレイアウトされていない場合)
if not frame:FindFirstChildOfClass("UIListLayout") then
local uiListLayout = Instance.new("UIListLayout")
uiListLayout.Parent = frame
end
フォントのサイクル
local textLabel = script.Parent
while true do
-- すべての異なるフォントをイテレートする
for _, font in pairs(Enum.Font:GetEnumItems()) do
textLabel.Font = font
textLabel.Text = font.Name
task.wait(1)
end
end

FontFace
並列読み取り
機能: UI
TextLabel.FontFace:Font

FontSize
非推奨

LineHeight
並列読み取り
機能: UI
TextLabel.LineHeight:number

LocalizedText
非表示
読み取り専用
複製されていません
並列読み取り
機能: UI
TextLabel.LocalizedText:string

MaxVisibleGraphemes
並列読み取り
機能: UI
TextLabel.MaxVisibleGraphemes:number

OpenTypeFeatures
並列読み取り
機能: UI
TextLabel.OpenTypeFeatures:string

OpenTypeFeaturesError
読み取り専用
複製されていません
並列読み取り
機能: UI
TextLabel.OpenTypeFeaturesError:string

RichText
並列読み取り
機能: UI
TextLabel.RichText:boolean

Text
並列読み取り
機能: UI
TextLabel.Text:string
コードサンプル
フェーディングバナー
local TweenService = game:GetService("TweenService")
local textLabel = script.Parent
local content = {
"私のゲームへようこそ!",
"楽しむことを忘れずに!",
"提案をお願いします!",
"他のプレイヤーに優しくしましょう!",
"他のプレイヤーを荒らさないでください!",
"ショップをチェックしてね!",
"ヒント:死なないで!",
}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local RNG = Random.new()
local fadeIn = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 0,
})
local fadeOut = TweenService:Create(textLabel, tweenInfo, {
TextTransparency = 1,
})
local lastIndex
while true do
-- ステップ 0: 何かをする前にフェードアウト
fadeOut:Play()
task.wait(tweenInfo.Time)
-- ステップ 1: 最後に表示したものではないコンテンツを選ぶ
local index
repeat
index = RNG:NextInteger(1, #content)
until lastIndex ~= index
-- 次回同じものを表示しないようにする
lastIndex = index
-- ステップ 2: コンテンツを表示
textLabel.Text = content[index]
fadeIn:Play()
task.wait(tweenInfo.Time + 1)
end
テキストの絵文字
local textLabel = script.Parent
local moods = {
["happy"] = "😃",
["sad"] = "😢",
["neutral"] = "😐",
["tired"] = "😫",
}
while true do
for mood, face in pairs(moods) do
textLabel.Text = "私は「" .. mood .. "!」と感じています。 " .. face
task.wait(1)
end
end

TextBounds
読み取り専用
複製されていません
並列読み取り
機能: UI
TextLabel.TextBounds:Vector2
コードサンプル
動的テキストボックスサイズ
local textBox = script.Parent
-- TextBoxの最小サイズ
local minWidth, minHeight = 10, 10
-- タイピング中にテキストが揺れないようにアラインメントを設定します
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top
local function updateSize()
textBox.Size = UDim2.new(0, math.max(minWidth, textBox.TextBounds.X), 0, math.max(minHeight, textBox.TextBounds.Y))
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)

TextColor
非推奨

TextColor3
並列読み取り
機能: UI
TextLabel.TextColor3:Color3
コードサンプル
カウントダウンテキスト
-- このコードを TextLabel/TextButton 内の LocalScript に配置します
local textLabel = script.Parent
-- TextColor3 で使用する色
local colorNormal = Color3.new(0, 0, 0) -- 黒
local colorSoon = Color3.new(1, 0.5, 0.5) -- 赤
local colorDone = Color3.new(0.5, 1, 0.5) -- 緑
-- 無限ループ
while true do
-- 10 から 1 まで逆にカウントダウン
for i = 10, 1, -1 do
-- テキストを設定
textLabel.Text = "時間: " .. i
-- 残り時間に基づいて色を設定
if i > 3 then
textLabel.TextColor3 = colorNormal
else
textLabel.TextColor3 = colorSoon
end
task.wait(1)
end
textLabel.Text = "スタート!"
textLabel.TextColor3 = colorDone
task.wait(2)
end

TextDirection
並列読み取り
機能: UI
TextLabel.TextDirection:Enum.TextDirection

TextFits
読み取り専用
複製されていません
並列読み取り
機能: UI
TextLabel.TextFits:boolean

TextScaled
並列読み取り
機能: UI
TextLabel.TextScaled:boolean

TextSize
並列読み取り
機能: UI
TextLabel.TextSize:number
コードサンプル
"カブーム!" テキスト
local textLabel = script.Parent
textLabel.Text = "カブーム!"
while true do
for size = 5, 100, 5 do
textLabel.TextSize = size
textLabel.TextTransparency = size / 100
task.wait()
end
task.wait(1)
end

TextStrokeColor3
並列読み取り
機能: UI
TextLabel.TextStrokeColor3:Color3

TextStrokeTransparency
並列読み取り
機能: UI
TextLabel.TextStrokeTransparency:number
コードサンプル
テキストハイライト振動
local textLabel = script.Parent
-- ハイライトがどれくらいの速さで点滅するべきか
local freq = 2
-- 黄色のハイライトカラーに設定
textLabel.TextStrokeColor3 = Color3.new(1, 1, 0)
while true do
-- math.sinは-1から1の間を振動するので、範囲を0から1に変更します:
local transparency = math.sin(workspace.DistributedGameTime * math.pi * freq) * 0.5 + 0.5
textLabel.TextStrokeTransparency = transparency
task.wait()
end

TextTransparency
並列読み取り
機能: UI
TextLabel.TextTransparency:number

TextTruncate
並列読み取り
機能: UI
TextLabel.TextTruncate:Enum.TextTruncate

TextWrap
非推奨

TextWrapped
並列読み取り
機能: UI
TextLabel.TextWrapped:boolean
コードサンプル
長いテキストラッピング
local textLabel = script.Parent
-- このテキストラッピングのデモは、200x50 px の長方形で示すのが最適です
textLabel.Size = UDim2.new(0, 200, 0, 50)
-- 綴るためのコンテンツ
local content = "これは、次第に UI 要素の幅を超える "
.. "長い単語の文字列です "
.. "改行を形成します。非常に長い段落に便利です。"
-- 2文字ずつテキストを綴る関数
local function spellTheText()
-- コンテンツの長さまで 1 から繰り返す
for i = 1, content:len() do
-- コンテンツの部分文字列を取得: 1 から i
textLabel.Text = content:sub(1, i)
-- テキストがボックスに収まらない場合は色を変更する
if textLabel.TextFits then
textLabel.TextColor3 = Color3.new(0, 0, 0) -- 黒
else
textLabel.TextColor3 = Color3.new(1, 0, 0) -- 赤
end
-- 偶数の長さで短い間隔を待つ
if i % 2 == 0 then
task.wait()
end
end
end
while true do
-- スケール/ラップなしでテキストを綴る
textLabel.TextWrapped = false
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- ラップありでテキストを綴る
textLabel.TextWrapped = true
textLabel.TextScaled = false
spellTheText()
task.wait(1)
-- テキストスケーリングのあるテキストを綴る
-- 注: テキストは赤に変わります (TextFits = false) はじめに UI 要素内に収まるように
-- スケールダウンする必要がある場合。
textLabel.TextScaled = true
-- 注: TextScaled = true のときに TextWrapped が暗黙的に有効になります
--textLabel.TextWrapped = true
spellTheText()
task.wait(1)
end

TextXAlignment
並列読み取り
機能: UI
TextLabel.TextXAlignment:Enum.TextXAlignment
コードサンプル
テキストの整列
-- これをTextLabel/TextButton/TextBox内のLocalScriptに貼り付けてください
local textLabel = script.Parent
local function setAlignment(xAlign, yAlign)
textLabel.TextXAlignment = xAlign
textLabel.TextYAlignment = yAlign
textLabel.Text = xAlign.Name .. " + " .. yAlign.Name
end
while true do
-- TextXAlignmentとTextYAlignmentの列挙型アイテムを両方繰り返します
for _, yAlign in pairs(Enum.TextYAlignment:GetEnumItems()) do
for _, xAlign in pairs(Enum.TextXAlignment:GetEnumItems()) do
setAlignment(xAlign, yAlign)
task.wait(1)
end
end
end

TextYAlignment
並列読み取り
機能: UI
TextLabel.TextYAlignment:Enum.TextYAlignment

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。