Is there a way to kick someone from the game automatically when they say a specific word or phrase in chat?
✓ ANSWER ACCEPTED
Is it possible to be kicked from the game automatically when something is said in chat?
1 answer
✓ Accepted answer
To check what the player chats, we use the Chatted event
game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
-- Code Here
end)
end)
Next, if you're looking for specific words, you need to break the message up into separate words with string.gmatch ["(%S+)" checks for spaces]
for cease in string.gmatch(string.lower(msg), "(%S+)") do
-- Code Here
end
To check for phrases, simply iterate over the message with string.match to look for a set of words which matches our censor
if string.match(string.lower(msg), chatted, 1) then
-- Code Here
end
Finally, if the censor returned a true value (the player said something we dont want them to say) we kick them
player:Kick("Inappropriate Language")
Example Server Script
local censor1 = {""} -- Words
local censor2 = {""} -- Phrases
game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local check = false
for index, chatted in pairs(censor1) do
for cease in string.gmatch(string.lower(msg), "(%S+)") do
if cease == chatted then
check = true
end
end
end
for index, chatted in pairs(censor2) do
if string.match(string.lower(msg), chatted, 1) then
check = true
end
end
if check == true then
player:Kick("Inappropriate Language")
end
end)
end)
In the above example, all words in the censor arrays should be lowercase (since we check with string.lower()
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
+1