さまざまなソースや入力に適用されるテキストフィルタリングは、ユーザーが不適切な言語や電話番号などの個人を特定できる情報を見るのを防ぎます。Robloxは、体験内テキストチャットを通過したメッセージのような一般的なテキスト出力を自動的にフィルタリングしますが、あなたが明示的に制御していない表示テキストのフィルタリングはあなたの責任です。
フィルタリングシナリオ
テキストは、以下のようなさまざまなシナリオでユーザーに収集および/または表示される可能性があります。
ランダムな文字から単語を生成し、それをユーザーに表示する体験。これにより、不適切な単語が生成される可能性があります。
外部Webサーバーに接続して、体験内に表示されるコンテンツを取得する体験。外部サイトのコンテンツを制御できないことが多く、第三者が情報を編集できる場合があります。
データストアを使用してユーザーのペットの名前などのテキストを保存する体験。保存されたテキストには、不適切な単語が含まれていて、取得時にフィルタリングされるべきものがあります。
フィルタリングプロセス
TextService:FilterStringAsync()は、テキストの文字列と、そのテキストを生成したユーザーのUserIdを入力として受け取り、体験内のテキストをフィルタリングします。これは、異なるシナリオで呼び出すことができる2つの追加メソッドを持つTextFilterResultオブジェクトを返します。
- TextFilterResult:GetNonChatStringForBroadcastAsync()は、サーバー上のすべてのユーザーに表示されるダイアログのようなテキストをフィルタリングするために使用されます。
- TextFilterResult:GetNonChatStringForUserAsync()は、特定のユーザーに対してフィルタリングされたテキストを表示するために使用され、年齢やその他の詳細に基づいています。
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")
-- フォーカスが失われ、Enterが押されたときのイベントハンドラー
local function onFocusLost(enterPressed, inputObject)
if enterPressed then
print("提出された:", 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("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("フィルタリングされた:", filteredText)
else
warn("テキストフィルタリング中のエラー!")
end
end
end
end
inputRemoteEvent.OnServerEvent:Connect(onInputReceived)