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.
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)
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.
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.