Help with detecting a word in the chat

Hey, I’m a new developer. I’m trying to make a script that detects if someone says “lol” in the chat and kill them, I’ve tried looking up how to do it but most of the answers were not related.

7 Likes

How to make a kick script when a specific chat has been said? - Help and Feedback / Scripting Support - Roblox Developer Forum

Player.Character,
Humanoid.Health,
Humanoid:TakeDamage()

You can use

player.Chatted:Connect(function(msg)

Example:

game:GetService('Players').PlayerAdded:Connect(function(plr)
   plr.Chatted:Connect(function(msg)
     print(plr.Name .. " has chatted! Message: " .. msg)
   end)
end)

It is in the developer hub in the post shown above. Their message is a string if that helps.

6 Likes

Here’s a script I wrote that should detect if “lol” is in the message.

local PlayersService = game:GetService("Players");
local StringToDetect = "lol";

PlayersService.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if string.find(string.lower(Message), string.lower(StringToDetect)) then
			if Player.Character then
				Player.Character.Humanoid.Health = 0;
			end;
		end;
	end);
end);
13 Likes

Are you looking for the method or for us to write the script for you?

I’m looking for a method and an example.

1 Like

Well, you would have to make a function when a player chatted something.

game.Players.PlayerAdded:Connect(function(player)
	
	player.Chatted:Connect(function(message)

Then if the player does chat something, check what it is.

if message == "Hello" then

After that, do what you want to happen when they say something.

-- Your code here --

		end
	end)
end)

Hope this helps!

6 Likes
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Connect(funtion()
local hum = char:WaitForChild('Humanoid')

game:GetService('Players').PlayerAdded:Connect(function(plr)
   plr.Chatted:Connect(function(msg)
         if msg:lower() == "lol" then
             hum:TakeDamage(100)
   end)
end)

Hopefully, it works, I don’t know because the dev forums don’t have a built-in output! :sweat_smile:

2 Likes