Ghi chú phát hành
Học
Lớp công cụ
TextService
Không Thể Tạo
Dịch Vụ
Không Sao Chép

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Phương Pháp
FilterAndTranslateStringAsync(stringToFilter: string,fromUserId: number,targetLocales: {any},textContext: Enum.TextFilterContext):TextFilterTranslatedResult
Đã Lỗi Thời
FilterStringAsync(stringToFilter: string,fromUserId: number,textContext: Enum.TextFilterContext):TextFilterResult
GetFamilyInfoAsync(assetId: ContentId):Dictionary
GetTextSize(string: string,fontSize: number,font: Enum.Font,frameSize: Vector2):Vector2
Thành viên kế thừa

Tài Liệu Tham Khảo API
Phương Pháp
FilterAndTranslateStringAsync
Đã Lỗi Thời

FilterStringAsync
Sinh Lợi
Các khả năng: UI
TextService:FilterStringAsync(
stringToFilter:string, fromUserId:number, textContext:Enum.TextFilterContext
Tham Số
stringToFilter:string
fromUserId:number
Giá Trị Mặc Định: "PrivateChat"
Lợi Nhuận
Mẫu mã
Ví dụ bộ lọc tên thú cưng
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
-- tạo một luồng mới để không làm chậm quá trình cập nhật
task.spawn(function()
-- lấy chuỗi đã lọc cho người dùng này
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
-- sử dụng pcall để bắt lỗi
local success, result = pcall(function()
return TextService:FilterStringAsync(petName, fromUserId)
end)
if success then
filterResults[fromUserId] = result
broadcastPetName(fromUserId)
else
print("Không thể lọc tên thú cưng")
end
end)
RequestAllPetNames.OnServerInvoke = function(player)
local toUserId = player.UserId
local petNames = {}
-- đi qua kết quả lọc và lọc tên thú cưng cần gửi
for fromUserId, filterResult in pairs(filterResults) do
local filteredString = filterResult:GetNonChatStringForUserAsync(toUserId)
filteredString = filteredString or ""
-- cần chuyển đổi userId sang chuỗi để không thể gửi thông qua hàm từ xa
petNames[tostring(fromUserId)] = filteredString
end
return petNames
end
Players.PlayerRemoving:Connect(function(oldPlayer)
local userId = oldPlayer.UserId
filterResults[userId] = nil
end)

GetFamilyInfoAsync
Sinh Lợi
Các khả năng: UI
TextService:GetFamilyInfoAsync(assetId:ContentId):Dictionary
Tham Số
assetId:ContentId
Lợi Nhuận
Mẫu mã
Lấy thông tin họ phông
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("Tên phông chữ:", info.Name)
print("Các kiểu mặt:")
for _, face in info.Faces do
print("--------")
print("Tên:", face.Name)
print("Trọng số:", face.Weight.Name)
print("Kiểu:", face.Style.Name)
end
end

GetTextBoundsAsync
Sinh Lợi
Các khả năng: UI
TextService:GetTextBoundsAsync(params:GetTextBoundsParams):Vector2
Tham Số
Lợi Nhuận
Mẫu mã
Đo kích thước văn bản
local TextService = game:GetService("TextService")
-- Khai báo tham số
local params = Instance.new("GetTextBoundsParams")
params.Text = "Xin chào thế giới!"
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
Các khả năng: UI
TextService:GetTextSize(
string:string, fontSize:number, font:Enum.Font, frameSize:Vector2
Tham Số
string:string
fontSize:number
frameSize:Vector2
Lợi Nhuận
Mẫu mã
Lấy Kích Thước Văn Bản
local TextService = game:GetService("TextService")
local function getTextBounds()
local message = "Xin chào thế giới!"
local size = Vector2.new(1, 1)
local bounds = TextService:GetTextSize(message, 12, "SourceSans", size)
return bounds
end
print(getTextBounds())

GetTextSizeOffsetAsync
Sinh Lợi
Các khả năng: UI
TextService:GetTextSizeOffsetAsync(
fontSize:number, font:Font
Tham Số
fontSize:number
font:Font
Lợi Nhuận
Mẫu mã
Lấy Kích Thước Văn Bản Bù
local TextService = game:GetService("TextService")
local label = script.Parent.TextLabel
-- Lấy giá trị bù điều chỉnh cho cài đặt kích thước văn bản ưa thích của người chơi
local success, offset = pcall(function()
return TextService:GetTextSizeOffsetAsync(label.TextSize, label.FontFace)
end)
if success then
-- Điều chỉnh chiều cao của nhãn bằng cách thêm giá trị bù
label.Size = UDim2.fromOffset(label.Size.X.Offset, label.Size.Y.Offset + offset)
end

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.