Message script Error

im trying to make it so that if you type a bad word,it changes the word to a good word!

local Words = {"BadWordOne", "BadWordTwo"}
local Good = {"Dekken"}

game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:Connect(function(Message)
        for i,v in pairs(Words)do
            if Message == v then
                print(Good) --  Put code here so the words in the message chagne to Dekken
            end
        end
    end)
end)
local List = {
  "Bad1" = "Good1",
  "Bad2" = "Good2"
}
game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:Connect(function(Message)
        for i,v in next, List do
            if Message:find(i) then
              Message:gsub(i,v)
            end
        end
        --Do whatever you want with the message now
    end)
end)
2 Likes

I’m not really answering your question here, but I do have something else to say: don’t do this. Custom filtering, even by means of circumventing tags by replacing words, is

  • Not scalable: You need to be able to account for the word itself, context and any other abomination of characters that could potentially allow a user to say a word they aren’t permitted to. This also means replacing inappropriate words with a corresponding good word, unless you feel like butchering a sentence altogether.

  • Not allowed: Custom filtering solutions are not allowed. Filtering a string via Roblox provided services (ChatService and TextService) do more than just filtering. Filter methods also collect logs so that when an in-game report is sent, moderators are able to review text logs of messages sent and act appropriately.

  • Improperly done: Switching inappropriate words with decent words isn’t going to do anything. The chat system already listens to chatted in a different mannerism. You’re collecting a modified chat that is localised to the function you’re connecting.

So what I’m trying to tell you is not to fix this at all and scrap it entirely. Use the proper services to filter text if you need to. You can then replace tags with something like [CENSORED] or whatever.

4 Likes

As @colbert2677 said, you should use roblox’s own filter instead, especially if you display the message to other players in any way.

Read more about it here:
-Text and Chat Filtering
-TextService:FilterStringAsync
-Chat:FilterStringForBroadcast

1 Like