I am working on my own chat system, and I have gotten to the part where I need to filter users’ messages, the only problem is, I can type in an inappropriate word and the word will get accepted. I am not sure why it is not working, I am using Roblox’s Developer page as reference.
Code:
(When a player sends a message, a remote event fires this code on the server)
local textObject
local success1, errorMessage1 = pcall(function()
textObject = _textService:FilterStringAsync(data1, player.UserId)
end)
if (success1) then
for _, chatPlayer in pairs(_players:GetPlayers()) do
local filteredTextResult = nil
local success2, errorMessage2 = pcall(function()
filteredTextResult = textObject:GetChatForUserAsync(chatPlayer.UserId)
end)
print(filteredTextResult, success2, errorMessage2)
if (success2) then
_remoteEvent:FireClient(chatPlayer, "plrMsg", filteredTextResult, player)
end
end
else
_remoteEvent:FireClient(player, "A problem occured while sending your message.", errorMessage1)
end
I realize that :GetChatForUserAsync()
allows you to filter words on different levels depending on the player that will be receiving the message, which is why I am looping through all the players to get their version of the message.