Hi there, back with another kick script needing help.
So this time I need help with this, why does my "kick on chat" script doesn't work?
01 | local canKick = { "LocalPlayer" } |
02 |
03 | game.Players.PlayerAdded:Connect( function (plr) |
04 | for _, c in pairs (canKick) do |
05 | if plr.Name = = c then |
06 | plr.Chatted:Connect( function (msg) |
07 | if string.sub(msg, 1 , 5 ) = = "Damn" then |
08 | local pl = game.Players:FindFirstChild(string.sub(msg, 7 )) |
09 | if pl then |
10 | pl:Kick( "Kicked for bad language." ) |
11 | end |
12 | end |
13 | end ) |
14 | end |
15 | end |
16 | end ) |
Just wanting help with this, just making a family friendly chat game! ;)
Thanks!
You would want to use other string methods so they can't bypass the filter so easily. The find and lower keywords would work good for this case.
01 | local Kickable = { "ThatPreston" } |
02 |
03 | game.Players.PlayerAdded:Connect( function (Player) |
04 | for _, Entry in pairs (Kickable) do |
05 | if Entry = = Player.Name then |
06 | Player.Chatted:Connect( function (Message) |
07 | Message = string.lower(Message) -- > make the message lowercase |
08 | if string.find(Message, "damn" ) then -- > check if damn is in the message |
09 | Player:Kick( "Kicked for bad language." ) -- > kick the player |
10 | end |
11 | end ) |
12 | break |
13 | end |
14 | end |
15 | end ) |
You'd want to put this script in ServerScriptService, ideally. You didn't clarify where or what your previous script was, but you'd typically want something like this on the server, in a normal script. I hope this helps! Good luck!