Myself personally I haven’t seen much on filtering textboxes that don’t give an in-depth answer of how to do it. Anyways here’s how you can do it. Hope this helps anyone.
-
Make a Remote Event in ReplicatedStorage. **Name it ‘FilterRE’ (Of course you can change it just change the paths in the code.) **
-
Make a Local Script as a child in your TextBox
-
Make a Server Script in ServerScriptService
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local remote = ReplicatedStorage:WaitForChild("FilterRE")
remote.OnServerEvent:Connect(function(player, message)
if type(message) ~= "string" or message == "" then
remote:FireClient(player, "")
return
end
local success, filteredText
pcall(function()
local filteredTextObject = TextService:FilterStringAsync(message, player.UserId)
filteredText = filteredTextObject:GetChatForUserAsync(player.UserId)
end)
if not success or not filteredText then
filteredText = "[Message failed to filter]"
end
remote:FireClient(player, filteredText)
end)
Local Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local remote = ReplicatedStorage:WaitForChild("FilterRE")
script.Parent.FocusLost:Connect(function(enterPressed)
if enterPressed then
local message = script.Parent.Text
if message and message ~= "" then
remote:FireServer(message)
end
end
end)
remote.OnClientEvent:Connect(function(filteredMessage)
if filteredMessage then
script.Parent.Text = filteredMessage
end
end)