So whenever I try filtering my chat message, there are 2 issues.
- It doesn't filter it
- It duplicates the message whenever it puts it in the chat area (if it is the 3rd message I make, there are 3 copies, and not one.)
Here is my code.
Client:
script.Parent.FocusLost:Connect(function(enter)
local enteredText = script.Parent.Text
if enter then
script.Parent.Text = ""
game.ReplicatedStorage.Events.FilterChatMessages:FireServer(enteredText)
game.ReplicatedStorage.Events.SendFilteredMessage.OnClientEvent:Connect(function(filteredText)
-- note: this part works and puts the text on my screen!
local text = Instance.new("TextLabel")
text.RichText = true
text.BorderSizePixel = 0
text.BackgroundColor3 = Color3.fromRGB(180, 180, 180)
text.TextColor3 = Color3.fromRGB(255, 255, 255)
text.BackgroundTransparency = 0.5
text.Text = '<b><i><font color="rgb(255,165,0)">'..game.Players.LocalPlayer.DisplayName..'; </font> '..filteredText..'</i></b>'
text.Parent = script.Parent.Parent.ChatArea
wait()
text.Size = UDim2.new(0, text.TextBounds.X, 0, text.TextBounds.Y)
end)
end
end)
Server:
local textService = game:GetService("TextService")
local filteredText
local result
game.ReplicatedStorage.Events.FilterChatMessages.OnServerEvent:Connect(function(player, text)
local success, errorMessage = pcall(function()
filteredText = textService:FilterStringAsync(text, player.UserId)
end)
if not success then
filteredText = "[Content Deleted]"
print(errorMessage)
end
if filteredText:IsA("TextFilterResult") then
result = filteredText:GetNonChatStringForBroadcastAsync()
if result ~= text then
print(result)
print(text)
result = "[Content Deleted]"
end
end
game.ReplicatedStorage.Events.SendFilteredMessage:FireClient(player, result)
end)
Please help!

3 comments
sorry for responding late, i'll try this sometime soon, rn i just don't feel like working on it lol
If it works then accept my answer.
thanks it works! i do have another question but i'm gonna make another question for that since its mostly unrelated to this.