We are able to add custom commands / filtering behavior quite easily. We want to start with creating a folder inside the Chat service. Name the folder exactly ChatModules and then insert a BoolValue and set it to true, Name it InsertDefaultModules
Now we can insert a module script inside ChatModules. The Chat System expects to receive a function so we want to do.
local function Run(ChatService)
end
return Run
After this we want to use a RegisterProcessCommandsFunction on ChatService, This requires a FunctionId we can just give it “Blacklist”. This will fire when the player chats, It will give you three variables speakerName, message, channelName, In the example I am giving I am just showing how you would blacklist a word but it can be used to make commands as well. We should have code that looks something like this.
local function Run(ChatService)
ChatService:RegisterProcessCommandsFunction("Blacklist", function(speakerName, message, channelName)
end)
end
return Run
Then the rest is quite simple, I made a table called BlacklistedWords that has one index with the key of “BadWord”. The intended purpose is that when you type “badword” into the chat it will not send. First i turned Message into lowercase just to avoid capitalization issues, Then I looped through the Blacklisted words and compared the message sent with the current key. If it was the the same I return true which will treat it as a command and not send. Outside the loop I return false which will process the command normally and send it. This is how my code turned out.
local BlockedWords = {“BadWord”}
local function Run(ChatService)
ChatService:RegisterProcessCommandsFunction("Blacklist", function(speakerName, message, channelName)
local messageLower = string.lower(message)
for every, word in pairs(BlockedWords) do
if string.find(messageLower, string.lower(word)) then
return true
end
end
return false
end)
end
return Run
If you have any questions or if this didn’t help just let me know
Used the resources from
Lua Chat System Wiki
Post by TheGamer101
Mentioning if this was your solution please mark it as solved