Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i add a filter to my custom chat?

Asked by
sad_eyez 162
7 years ago

I need to add a filter so my game doesn't get moderated or anything.

local storage = game.Workspace.ChatStorage
local ChatService = game:GetService("Chat")

game.Players.PlayerAdded:connect(function(plr)
    wait(0.1)
    local newplayer = Instance.new("StringValue",storage)
    newplayer.Name = plr.Name.." Has joined the server!"
    plr.Chatted:connect(function(msg)
        local message = Instance.new("StringValue",storage)
        message.Name = plr.Name..": "..msg
    end)
end)

while wait(300) do
    for i,v in pairs(storage:GetChildren()) do
        v:Destroy()
    end
end

2 answers

Log in to vote
0
Answered by 7 years ago

I know its ugly but just try this: http://wiki.roblox.com/index.php?title=Custom_chat_GUI I looked at it first and thought how ugly it was but tried it and it worked; if you have any question ask:)

Ad
Log in to vote
4
Answered by 7 years ago

Expanding upon the previous answer, there are two functions which are important: FilterStringAsync and FilterStringForBroadcast. They both function very similarly, but with slightly different parameters. They are both members of the Chat service.

FilterStringAsync has three parameters:

  • The first is simply the string to be filtered.
  • The second is the player who is sending the message.
  • The third is the player who is receiving the message.

However, if you don't know (or care) who the message is being sent to, as is likely the case with your chat system, you may prefer FilterStringForBroadcast. It is similar to the previous function, but with only two arguments: the string to be filtered, and the player sending the message. The idea is that the string returned by it will be acceptable for anyone to see regardless of their chat settings.

More information on these functions can be found here.

Hopefully this is what you are looking for.

Also, apologies for going a bit off-topic, but I noticed this code here:

while wait(300) do
    for i,v in pairs(storage:GetChildren()) do
        v:Destroy()
    end
end

This code looks like it could be implemented in a better way. I would suggest looking into the Debris service.

Answer this question