How to implement Roblox's text filtering

Hi ya’ll,

I have problem because I do not have any idea how to implement the roblox’s text filtering into my chat system, I’ve tried to implemet kinda custom filtering system but no chance. Bellow I’ll leave 2 of the scripts powering whole chat system:

Server script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local serverEvent = ReplicatedStorage:WaitForChild("ServerEvent")
local TextService = game:GetService("TextService")
local HttpService = game:GetService("HttpService")
local badWordsUrl = "https://clippsly.com/sys/bwords.json"
local badWords = {}

local function loadBadWords()
	local response = HttpService:GetAsync(badWordsUrl)
	local data = HttpService:JSONDecode(response)
	if data then
		for _, word in ipairs(data) do
			badWords[word] = true
		end
	end
end

local function containsBadWords(message)
	for word in message:gmatch("%S+") do
		if badWords[word] then
			return true
		end
	end
	return false
end

local function moderateMessage(message)
	local moderatedMessage = message
	for word in message:gmatch("%S+") do
		if badWords[word] then
			moderatedMessage = moderatedMessage:gsub(word, "This message have been moderated because it contained inappropriate language.")
		end
	end
	return moderatedMessage
end

loadBadWords()

local function onMessageReceived(sender, message)
	print("ClipMessage: New message: "..sender.Name, message)
	local moderatedMessage = message
	if containsBadWords(message) then
		moderatedMessage = moderateMessage(message)
	end
	for _, otherPlayer in pairs(Players:GetPlayers()) do
		if otherPlayer ~= sender then
			serverEvent:FireClient(otherPlayer, sender.Name, moderatedMessage)
		end
	end
end

serverEvent.OnServerEvent:Connect(onMessageReceived)

Local script:

local window = script.Parent.Parent.WindowManager.cMessage
local chatLog = window.ChatLog
local messageBox = window.MesgBar
local msgFrame = game.ReplicatedStorage.MsgFrame
local notif = script.Parent.Parent.DockShelf.BMessages.Notif
local notifSound = script.Parent.Parent.Background.Notif
local sentSound = script.Parent.Parent.Background.Sent

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local serverEvent = game.ReplicatedStorage:WaitForChild("ServerEvent")

local function addMessageToChatLog(senderName, message)
	local newMsgFrame = msgFrame:Clone()
	newMsgFrame.Parent = chatLog

	local sndr = newMsgFrame.Sndr
	sndr.Value = senderName
	local clr = newMsgFrame.BackgroundColor3
	clr = Color3.fromRGB(25, 130, 252)
	local msgText = newMsgFrame.MsgText
	msgText.Text = message
	local userName = newMsgFrame.UsrName
	userName.Text = senderName
	local roleclr = newMsgFrame.RoleColor

	print("ClipMessage: Message successfully sent.")

	if LocalPlayer.Name ~= senderName then
		notif.Visible = true
		notifSound:Play()
	else
		sentSound:Play()
	end
end

local function sendMessage()
	local message = messageBox.Text
	if message ~= "" then
		chatLog.CanvasPosition = Vector2.new(0,9999)
		serverEvent:FireServer(message, LocalPlayer.Name)
		messageBox.Text = ""
		addMessageToChatLog(LocalPlayer.Name, message)
	end
end

messageBox.FocusLost:Connect(sendMessage)

serverEvent.OnClientEvent:Connect(function(senderName, message)
	addMessageToChatLog(senderName, message)
end)

I’ll be soo gratefull if someone could tell me where should I start implementing it and how.

Thanks for help in advance,
~ SG

Hey, in general it’s not a good idea to ask the community to implement features for you, just warning you, HOWEVER, I would like to tell you since it was frustrating for me too! First of all, it doesn’t work in studio. so you have to test it ingame. Second of all, there are many topics that have already been created, pelase search first before creating a topic! How do you filter text? - Help and Feedback / Scripting Support - Developer Forum | Roblox

Hi,

I’m not asking community to do it for me, I’m asking if someone could tell me as I’ve stated at the bottom of the post: “I’ll be soo gratefull if someone could tell me where should I start implementing it and how.”

Best,
~ SG

You might be interested in reverse-engineering the chat system I developed.

1 Like

Link doesn’t work. :man_shrugging:

edit: it seems to be working now.

Yep, realised that as I clicked it - just edited my post :slight_smile:

This should help:

(The text filtering is located under Methods)