HELP Custom Chat with Filtering

Hello !
I find on youtube a tutorial for making a custom chat. I follow step by step, and it works pretty well, but actually, this chat doesn’t have any form of filtering. So i search for making a filter for my chat, but actually, i doesnt work. Can you help me please ?

ServiceScriptService :

local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

local TextService = game:GetService("TextService")

event.OnServerEvent:Connect(function(plr,message)

if message ~= "" then

event:FireAllClients(message, plr.Name)

end

end)

Local script in StarterGui :

local textbox = script.Parent.Send.TextBox

local holder = script.Parent.Holder

local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

local template = game:GetService("ReplicatedStorage"):WaitForChild("temp")

textbox.FocusLost:Connect(function(ep)

if (ep) and textbox.Text ~= "" then

event:FireServer(textbox.Text)

textbox.Text = ""

else

warn("Please enter text.")

end

end)

event.OnClientEvent:Connect(function(message,plrThatSent)

local clone = template:Clone()

clone.plr.Text = "[" .. plrThatSent .. "]:"

clone.message.Text = message

clone.Parent = script.Parent.Holder

end)

One thing I know is that the filter must be placed before the moment when i fire all the clients.

1 Like

You can do FilterStringAsync().
For more information, you can go to Text Filtering | Roblox Creator Documentation
Hope it helps!

2 Likes

Yes thank you, i already search, but its hard to use haha xd if you have some idea i take :slight_smile:

1 Like

You can use Chat | Roblox Creator Documentation
Script:

local Chat = game:GetService("Chat")

game.ReplicatedStorage.FilterMessage.OnServerEvent:Connect(function(player, message)
	if utf8.len(message) > 0 then
		local result = Chat:FilterStringForBroadcast(message, player)
		game.ReplicatedStorage.FilterMessage:FireAllClients(player, result)
	end
end)

LocalScript:

local result = game.ReplicatedStorage.FilterMessage:FireServer("hello") -- message to be filtered

game.ReplicatedStorage.FilterMessage.OnClientEvent:Connect(function(player, message)
	print("Recipent: " .. player.Name .. " Message: " .. message)
end)
1 Like

okay thx ! i test right now :slight_smile:

but how can i mixt i with the script I use ?

Just use the InvokeServer in the remote function to filter the message. If you want, you can show the code to help you.

Edit:
Don’t use remote function, use remote event instead.

1 Like

So as you can see I add the InvokeServer but i got an error :

17:34:35.308 FilterMessage is not a valid member of ReplicatedStorage "ReplicatedStorage" - Client - LocalScript:9

You need to insert a remote event in replicatedstorage and call it FilterMessage. I fixed the code now using a remote event.

1 Like

im lost haha xd what did i do xd in order ( im sorry )

Remove the variable result and remove the print because now it will return nothing.

And in the onclientevent the first parameter is the player and the second parameter is the message

And in the clone.plr.Text put:

clone.plr.Text = "[" .. plrThatSent.Name .. "]: " .. message

Also remember that the script must be in the serverscriptservice

No, please use this tutorial instead @Moldard :

1 Like

it looks difficult but okay i will try thx !

This is better as it uses an asynchronous thread. ChatService does not meaning that you’d have to make your own function to wait until it finished running the filter.

1 Like


I try this but obviously it doesnt work … x)

Your never calling getTextObject or getFilteredMessage also :GetChatForUserAsync requires it to be sent to one individual user, use Broadcast if your going to do it for the full server.

1 Like

woah :o you lost me xd too difficult for me i think xd

If you want to use :FireAllClients() you’ll need to use: TextFilterResult | Roblox Creator Documentation

1 Like

ok but i use it where ? im lost haha

Here is a tutorial on text filtering: A Guide to Filtering Text

1 Like