Is there a way to kick someone from the game automatically when they say a specific word or phrase in chat?
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()
Closed as Not Constructive by TheeDeathCaster
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?