How to make a kick script when a specific chat has been said?

I want to make a script that has multiple chat messages that will kick people from the game if they say it.

An example would be if a player says “robux please” the player will be kicked.

If this topic doesn’t fit in this category please don’t get mad at me and just tell me where to post this instead :sweat_smile:

2 Likes

uh you could do something like

local Words_To_Kick_Player = {
	["kick me"] = true; -- it's essential you keep the messages in this format when adding a new one, with the brackets and = true, it helps identify the message thats being passed as a parameter!
};

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(msg)
		local input = string.lower(msg);
		if Words_To_Kick_Player[input] then
			Player:Kick("Bye-Bye!");
		end
	end)
end)

hope this helps!

(also this is my first post, hope this helps :smile:!)

edit: if you’re looking to segment text FROM a players text, you could try and do this too

local Words_To_Kick_Player = {
    "kick me";
};

game.Players.PlayerAdded:Connect(function(Player)
    Player.Chatted:Connect(function(msg)
        local input = string.lower(msg);

        for k,v in next, (Words_To_Kick_Player) do
            if input:find(v) then
                Player:Kick("Bye!!!");
            end
        end

    end)
end)
4 Likes

Instead of using the desired words as indexes, wouldn’t it be more efficient to just use them as values? I don’t see a purpose for indexing each words as true within the table.

1 Like

you’re right. my bad! sorry, i wasn’t really paying attention, let me fix that :sweat_smile:

there we go, that should be better now.

1 Like