Aprenda
Classe do mecanismo
TextService
Não criável
Serviço
Não replicado

*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.


Resumo
Métodos
FilterAndTranslateStringAsync(stringToFilter: string,fromUserId: number,targetLocales: {any},textContext: Enum.TextFilterContext):TextFilterTranslatedResult
Obsoleto
FilterStringAsync(stringToFilter: string,fromUserId: number,textContext: Enum.TextFilterContext):TextFilterResult
GetFamilyInfoAsync(assetId: ContentId):Dictionary
GetTextSize(string: string,fontSize: number,font: Enum.Font,frameSize: Vector2):Vector2
Membros herdados

Referência API
Métodos
FilterAndTranslateStringAsync
Obsoleto

FilterStringAsync
Rendimentos
Recursos: UI
TextService:FilterStringAsync(
stringToFilter:string, fromUserId:number, textContext:Enum.TextFilterContext
Parâmetros
stringToFilter:string
fromUserId:number
Valor Padrão: "PrivateChat"
Devolução
Amostras de código
Exemplo de Filtro de Nome de Animal de Estimação
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
-- criar uma nova thread para não atrasar a atualização
task.spawn(function()
-- pegar a string filtrada para este usuário
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 para capturar erros
local success, result = pcall(function()
return TextService:FilterStringAsync(petName, fromUserId)
end)
if success then
filterResults[fromUserId] = result
broadcastPetName(fromUserId)
else
print("Não foi possível filtrar o nome do animal de estimação")
end
end)
RequestAllPetNames.OnServerInvoke = function(player)
local toUserId = player.UserId
local petNames = {}
-- percorrer os resultados do filtro e filtrar o nome do animal de estimação a ser enviado
for fromUserId, filterResult in pairs(filterResults) do
local filteredString = filterResult:GetNonChatStringForUserAsync(toUserId)
filteredString = filteredString or ""
-- precisar converter userId para string para que não possa ser enviado via uma função remota
petNames[tostring(fromUserId)] = filteredString
end
return petNames
end
Players.PlayerRemoving:Connect(function(oldPlayer)
local userId = oldPlayer.UserId
filterResults[userId] = nil
end)

GetFamilyInfoAsync
Rendimentos
Recursos: UI
TextService:GetFamilyInfoAsync(assetId:ContentId):Dictionary
Parâmetros
assetId:ContentId
Devolução
Amostras de código
Obter Informações da Família de Fonte
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("Nome da fonte:", info.Name)
print("Faces:")
for _, face in info.Faces do
print("--------")
print("Nome:", face.Name)
print("Peso:", face.Weight.Name)
print("Estilo:", face.Style.Name)
end
end

GetTextBoundsAsync
Rendimentos
Recursos: UI
TextService:GetTextBoundsAsync(params:GetTextBoundsParams):Vector2
Parâmetros
Devolução
Amostras de código
Medindo o Tamanho do Texto
local TextService = game:GetService("TextService")
-- Declarar parâmetros
local params = Instance.new("GetTextBoundsParams")
params.Text = "Olá mundo!"
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
Recursos: UI
TextService:GetTextSize(
string:string, fontSize:number, font:Enum.Font, frameSize:Vector2
Parâmetros
string:string
fontSize:number
frameSize:Vector2
Devolução
Amostras de código
Obtendo Tamanho do Texto
local TextService = game:GetService("TextService")
local function getTextBounds()
local message = "Olá mundo!"
local size = Vector2.new(1, 1)
local bounds = TextService:GetTextSize(message, 12, "SourceSans", size)
return bounds
end
print(getTextBounds())

GetTextSizeOffsetAsync
Rendimentos
Recursos: UI
TextService:GetTextSizeOffsetAsync(
fontSize:number, font:Font
Parâmetros
fontSize:number
font:Font
Devolução
Amostras de código
Obter Deslocamento do Tamanho do Texto
local TextService = game:GetService("TextService")
local label = script.Parent.TextLabel
-- Obter deslocamento ajustado para a configuração de tamanho de texto preferida do jogador
local success, offset = pcall(function()
return TextService:GetTextSizeOffsetAsync(label.TextSize, label.FontFace)
end)
if success then
-- Ajustar altura principal do rótulo adicionando o deslocamento
label.Size = UDim2.fromOffset(label.Size.X.Offset, label.Size.Y.Offset + offset)
end

©2026 Roblox Corporation, Roblox, o logotipo Roblox e Powering Imagination estão entre nossas marcas registradas e não registradas nos EUA e em outros países.