Informacje o wersji
Edukacja
Klasa silnika
TextService
Brak możliwości tworzenia
Usługa
Bez replikacji

*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.


Podsumowanie
Metody
FilterAndTranslateStringAsync(stringToFilter: string,fromUserId: number,targetLocales: {any},textContext: Enum.TextFilterContext):TextFilterTranslatedResult
Przestarzałe
FilterStringAsync(stringToFilter: string,fromUserId: number,textContext: Enum.TextFilterContext):TextFilterResult
GetFamilyInfoAsync(assetId: ContentId):Dictionary
GetTextSize(string: string,fontSize: number,font: Enum.Font,frameSize: Vector2):Vector2
Członkowie odziedziczeni

Materiały referencyjne dotyczące interfejsów API
Metody
FilterAndTranslateStringAsync
Przestarzałe

FilterStringAsync
Wynik
Możliwości: UI
TextService:FilterStringAsync(
stringToFilter:string, fromUserId:number, textContext:Enum.TextFilterContext
Parametry
stringToFilter:string
fromUserId:number
Wartość domyślna: "PrivateChat"
Przykłady kodu
Przykład Filtru Nazwy Pupila
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
-- uruchom nowy wątek, aby nie wstrzymywać aktualizacji
task.spawn(function()
-- pobierz przefiltrowany ciąg dla tego użytkownika
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, aby złapać błędy
local success, result = pcall(function()
return TextService:FilterStringAsync(petName, fromUserId)
end)
if success then
filterResults[fromUserId] = result
broadcastPetName(fromUserId)
else
print("Nie można przefiltrować nazwy pupila")
end
end)
RequestAllPetNames.OnServerInvoke = function(player)
local toUserId = player.UserId
local petNames = {}
-- przejrzyj wyniki filtrowania i przefiltruj nazwę pupila do wysłania
for fromUserId, filterResult in pairs(filterResults) do
local filteredString = filterResult:GetNonChatStringForUserAsync(toUserId)
filteredString = filteredString or ""
-- trzeba zamienić userId na ciąg, aby nie można było go wysłać przez funkcję zdalną
petNames[tostring(fromUserId)] = filteredString
end
return petNames
end
Players.PlayerRemoving:Connect(function(oldPlayer)
local userId = oldPlayer.UserId
filterResults[userId] = nil
end)

GetFamilyInfoAsync
Wynik
Możliwości: UI
TextService:GetFamilyInfoAsync(assetId:ContentId):Dictionary
Parametry
assetId:ContentId
Przykłady kodu
Uzyskaj informacje o rodzinie czcionek
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("Nazwa czcionki:", info.Name)
print("Style:")
for _, face in info.Faces do
print("--------")
print("Nazwa:", face.Name)
print("Waga:", face.Weight.Name)
print("Styl:", face.Style.Name)
end
end

GetTextBoundsAsync
Wynik
Możliwości: UI
TextService:GetTextBoundsAsync(params:GetTextBoundsParams):Vector2
Parametry
Zwroty
Przykłady kodu
Mierzenie rozmiaru tekstu
local TextService = game:GetService("TextService")
-- Deklaruj parametry
local params = Instance.new("GetTextBoundsParams")
params.Text = "Witaj świecie!"
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
Możliwości: UI
TextService:GetTextSize(
string:string, fontSize:number, font:Enum.Font, frameSize:Vector2
Parametry
string:string
fontSize:number
frameSize:Vector2
Zwroty
Przykłady kodu
Uzyskiwanie rozmiaru tekstu
local TextService = game:GetService("TextService")
local function getTextBounds()
local message = "Witaj świecie!"
local size = Vector2.new(1, 1)
local bounds = TextService:GetTextSize(message, 12, "SourceSans", size)
return bounds
end
print(getTextBounds())

GetTextSizeOffsetAsync
Wynik
Możliwości: UI
TextService:GetTextSizeOffsetAsync(
fontSize:number, font:Font
Parametry
fontSize:number
font:Font
Zwroty
Przykłady kodu
Uzyskaj przesunięcie rozmiaru tekstu
local TextService = game:GetService("TextService")
local label = script.Parent.TextLabel
-- Uzyskaj przesunięcie dostosowane do preferencji rozmiaru tekstu gracza
local success, offset = pcall(function()
return TextService:GetTextSizeOffsetAsync(label.TextSize, label.FontFace)
end)
if success then
-- Dostosuj wysokość podstawową etykiety, dodając przesunięcie
label.Size = UDim2.fromOffset(label.Size.X.Offset, label.Size.Y.Offset + offset)
end

©2026 Roblox Corporation. Nazwa Roblox, logo Roblox oraz hasło „Powering Imagination” należą do naszych zarejestrowanych i niezarejestrowanych znaków towarowych na terenie Stanów Zjednoczonych oraz w innych krajach.