テキストフィルター

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

様々なソースや入力に適用される テキストフィルタリング は、ユーザーが不適切な言語や電話番号などの個人識別情報を見るのを防ぎます。Roblox は、インエクスペリエンステキストチャット を通過したメッセージなどの一般的なテキスト出力を自動的にフィルタリングしますが、 あなたは明示的に制御できない表示されたテキストをフィルタリングする責任があります

シナリオをフィルターする

テキストは、さまざまなシナリオでユーザーに収集および/または表示されることがあります:

  • ユーザーの テキスト入力 を通じて TextBox エントリで集めるエクスペリエンス、キーボード/キーパッドインターフェイスのようなカスタム GUI、または 3D 空間内のインタラクティブキーボードモデル。

  • ランダムな文字から単語を生成し、ユーザーに表示する経験、不適切な単語が生成される可能性があるため。

  • エクスペリエンスに接続して外部ウェブサーバーにコンテンツを取得する体験。体験内に表示されるコンテンツを取得する。外部サイトのコンテンツを制御できないことが多く、第三者が情報を編集できます。

  • ユーザーのペット名などのテキストを保存する データストア を使用して、保存されたテキストに、回収すると不適切な言葉が含まれる可能性があるものを含める経験。

フィルタリングプロセス

TextService:FilterStringAsync() 経験中のテキストをフィルターするには、テキストのストリングと、テキストを作成したユーザーの UserId を入力として取り、それは、異なるシナリオで呼び出すことができる 2つの追加メソッドを持つ TextFilterResult オブジェクトを返します:

TextBox 入力のコンテキストで、次の例は FocusLost イベントの入力を収集し、RemoteEvent を介してサーバーに送信します。サーバー上では、FilterStringAsync() を経由して最初にフィルタリングされ、次に GetNonChatStringForBroadcastAsync() で 3D ワールドのサーバー側オブジェクトのようなすべてのユーザーにテキストが表示される意図で SurfaceGui を経由します。

テキスト入力のフィルタリング - クライアントスクリプト

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local textBox = script.Parent
textBox.ClearTextOnFocus = false
textBox.PlaceholderText = "..."
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextScaled = true
-- リモートイベントでテキスト入力をサーバーに送信してフィルタリングする
local inputRemoteEvent = ReplicatedStorage:FindFirstChild("InputRemoteEvent")
-- 焦点が失われて入力が押されているイベントハンドラー
local function onFocusLost(enterPressed, inputObject)
if enterPressed then
print("SUBMITTED:", textBox.Text)
if inputRemoteEvent then
inputRemoteEvent:FireServer(textBox.Text)
end
end
end
textBox.FocusLost:Connect(onFocusLost)
テキスト入力のフィルタリング - サーバースクリプト

local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- リモートイベントを受信して、クライアントからのテキスト入力をフィルタリングする
local inputRemoteEvent = ReplicatedStorage:FindFirstChild("InputRemoteEvent")
local function getFilterResult(text, fromUserId)
local filterResult
local success, errorMessage = pcall(function()
filterResult = TextService:FilterStringAsync(text, fromUserId)
end)
if success then
return filterResult
else
warn("Error generating TextFilterResult:", errorMessage)
end
end
-- クライアントが TextBox からの入力を送信すると発射される
local function onInputReceived(player, text)
if text ~= "" then
local filterResult = getFilterResult(text, player.UserId)
if filterResult then
local success, filteredText = pcall(function()
return filterResult:GetNonChatStringForBroadcastAsync()
end)
if success then
print("FILTERED:", filteredText)
else
warn("Error filtering text!")
end
end
end
end
inputRemoteEvent.OnServerEvent:Connect(onInputReceived)