Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you detect wether a player chatted a certain word?

So, I've been trying to do chat commands and stuff, but when you say the command word in a sentence it doesn't activate. I THINK you have to use :match() for this? I don't know, so could anyone help me out? Here's the test code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
player.Chatted:Connect(function(message)
	if message:lower() == "lumos" then
		game.ReplicatedStorage.LumosEvent:FireServer(mouse.Hit.p)
	end
end)

1 comment

0

The code itself works fine, I just don't know how to detect the command word in a statement

2 answers

✓ Accepted answer

You can use string.sub,string.match, or string.find, most likely string.match or string.find

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
player.Chatted:Connect(function(message)
       if (message:lower()):match('lumos') then
              game.ReplicatedStorage.LumosEvent:FireServer(mouse.Hit.p)
       end
end)

You can use the message argument.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

player.Chatted:connect(function(msg)
            if msg = string.lower("lumos") then
		 	game:GetService("ReplicatedStorage").LumosEvent:FireServer(mouse.Hit.p)
	    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.