If player sends a message, kick the same player

Hey there! I’m trying to make a script that kicks a player for sending a specific message, but it doesn’t works, here’s the script:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg:lower() == "this game is so boring" then
			player:Kick("no u")
		end
	end)
end)

I would also like to know if the script can check the message for specific words, but how can i fix this?

2 Likes

is it a localscript?
any error?

It’s a Script in ServerScriptService, and no errors

instead of msg:lower try using msg ==

local Players = game:GetService('Players')

function playerAdded(p)
   p.Chatted:Connect(function(msg)
      if msg:lower() == "banana aplocalypse" then
        p:Kick('i will kick a banana')
     end
   end)
end

for _, player in next, Players:GetPlayers() do
  playerAdded(player)
end

Players.PlayerAdded:Connect(playerAdded)
3 Likes

he already used :lower()


1 Like

Use str:find(word) or string.find(str, word):

local strExample = "i liek piez"
print(strExample:find("piez")) --> true
print(string.find(strExample, "pierogi")) --> false

@p49p0 Please don’t use next, as in Luau it doesn’t have optimizations that pairs() does. (while I’m at it, don’t use global functions!)

just saying, it does the same result and for me next is shorter to type

Yes. But it doesn’t have optimizations that pairs() does.

yeah, i think so. thanks for the information…?