เรียนรู้
Engine Class
TextService
ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
วิธีการ
FilterAndTranslateStringAsync(stringToFilter: string,fromUserId: number,targetLocales: {any},textContext: Enum.TextFilterContext):TextFilterTranslatedResult
เลิกใช้แล้ว
FilterStringAsync(stringToFilter: string,fromUserId: number,textContext: Enum.TextFilterContext):TextFilterResult
GetFamilyInfoAsync(assetId: ContentId):Dictionary
GetTextSize(string: string,fontSize: number,font: Enum.Font,frameSize: Vector2):Vector2
สมาชิกที่ได้รับทอด

เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
FilterAndTranslateStringAsync
เลิกใช้แล้ว

FilterStringAsync
ผลตอบแทน
ความสามารถ: UI
TextService:FilterStringAsync(
stringToFilter:string, fromUserId:number, textContext:Enum.TextFilterContext
พารามิเตอร์
stringToFilter:string
fromUserId:number
ค่าเริ่มต้น: "PrivateChat"
ส่งค่ากลับ
ตัวอย่างโค้ด
ตัวอย่างการกรองชื่อสัตว์เลี้ยง
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local Remotes = Instance.new("Folder")
Remotes.Name = "PetNamingRemotes"
Remotes.Parent = ReplicatedStorage
local UserNamedPet = Instance.new("RemoteEvent")
UserNamedPet.Name = "UserNamedPet"
UserNamedPet.Parent = Remotes
local SendPetName = Instance.new("RemoteEvent")
SendPetName.Name = "SendPetName"
SendPetName.Parent = Remotes
local RequestAllPetNames = Instance.new("RemoteFunction")
RequestAllPetNames.Name = "RequestAllPetNames"
RequestAllPetNames.Parent = Remotes
local filterResults = {}
local function broadcastPetName(userId)
local filterResult = filterResults[userId]
if filterResult then
for _, player in pairs(Players:GetPlayers()) do
if player then
-- เริ่มเธรดใหม่เพื่อไม่ให้หยุดการอัปเดต
task.spawn(function()
-- ดึงสตริงที่กรองสำหรับผู้ใช้รายนี้
local toUserId = player.UserId
local filteredString = filterResult:GetNonChatStringForUserAsync(toUserId)
filteredString = filteredString or ""
SendPetName:FireClient(player, userId, filteredString)
end)
end
end
end
end
UserNamedPet.OnServerEvent:Connect(function(player, petName)
local fromUserId = player.UserId
-- pcall เพื่อตรวจจับข้อผิดพลาด
local success, result = pcall(function()
return TextService:FilterStringAsync(petName, fromUserId)
end)
if success then
filterResults[fromUserId] = result
broadcastPetName(fromUserId)
else
print("ไม่สามารถกรองชื่อสัตว์เลี้ยงได้")
end
end)
RequestAllPetNames.OnServerInvoke = function(player)
local toUserId = player.UserId
local petNames = {}
-- ตรวจสอบผลการกรองและกรองชื่อสัตว์เลี้ยงที่จะส่ง
for fromUserId, filterResult in pairs(filterResults) do
local filteredString = filterResult:GetNonChatStringForUserAsync(toUserId)
filteredString = filteredString or ""
-- ต้องแปลง userId เป็นสตริงเพื่อไม่ให้สามารถส่งผ่านฟังก์ชันระยะไกลได้
petNames[tostring(fromUserId)] = filteredString
end
return petNames
end
Players.PlayerRemoving:Connect(function(oldPlayer)
local userId = oldPlayer.UserId
filterResults[userId] = nil
end)

GetFamilyInfoAsync
ผลตอบแทน
ความสามารถ: UI
TextService:GetFamilyInfoAsync(assetId:ContentId):Dictionary
พารามิเตอร์
assetId:ContentId
ส่งค่ากลับ
ตัวอย่างโค้ด
ข้อมูลฟอนต์
local TextService = game:GetService("TextService")
local familyToCheck = "rbxasset://fonts/families/Arimo.json"
local success, info = pcall(function()
return TextService:GetFamilyInfoAsync(familyToCheck)
end)
if success then
print("ชื่อฟอนต์:", info.Name)
print("ฟอนต์ต่างๆ:")
for _, face in info.Faces do
print("--------")
print("ชื่อ:", face.Name)
print("น้ำหนัก:", face.Weight.Name)
print("สไตล์:", face.Style.Name)
end
end

GetTextBoundsAsync
ผลตอบแทน
ความสามารถ: UI
TextService:GetTextBoundsAsync(params:GetTextBoundsParams):Vector2
พารามิเตอร์
ส่งค่ากลับ
ตัวอย่างโค้ด
การวัดขนาดข้อความ
local TextService = game:GetService("TextService")
-- ประกาศพารามิเตอร์
local params = Instance.new("GetTextBoundsParams")
params.Text = "สวัสดีโลก!"
params.Font = Font.new("rbxasset://fonts/families/GrenzeGotisch.json", Enum.FontWeight.Thin)
params.Size = 20
params.Width = 200
local success, bounds = pcall(function()
return TextService:GetTextBoundsAsync(params)
end)
if success then
print(bounds)
end

GetTextSize
ความสามารถ: UI
TextService:GetTextSize(
string:string, fontSize:number, font:Enum.Font, frameSize:Vector2
พารามิเตอร์
string:string
fontSize:number
frameSize:Vector2
ส่งค่ากลับ
ตัวอย่างโค้ด
การรับขนาดข้อความ
local TextService = game:GetService("TextService")
local function getTextBounds()
local message = "สวัสดีโลก!"
local size = Vector2.new(1, 1)
local bounds = TextService:GetTextSize(message, 12, "SourceSans", size)
return bounds
end
print(getTextBounds())

GetTextSizeOffsetAsync
ผลตอบแทน
ความสามารถ: UI
TextService:GetTextSizeOffsetAsync(
fontSize:number, font:Font
พารามิเตอร์
fontSize:number
font:Font
ส่งค่ากลับ
ตัวอย่างโค้ด
ขนาดข้อความที่ตั้ง offset
local TextService = game:GetService("TextService")
local label = script.Parent.TextLabel
-- รับการปรับ offset ตามการตั้งค่าขนาดข้อความที่ผู้เล่นเลือก
local success, offset = pcall(function()
return TextService:GetTextSizeOffsetAsync(label.TextSize, label.FontFace)
end)
if success then
-- ปรับความสูงหลักของ label โดยการเพิ่ม offset
label.Size = UDim2.fromOffset(label.Size.X.Offset, label.Size.Y.Offset + offset)
end

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ