How would I find a specific word in a player's chat?

Hello. I am trying to make voice chats using the .Chatted event, but for some reason it does work but if I put a period at the end of the word it won’t work. I don’t want to add new strings to the table that is just the same thing but with a period.

local debounce = false
local cChats = {
	"help",
	"moving foward"
}

local function onPlayerChatted(player, message)
	if player.Character:FindFirstChild("Head") and not debounce and player.Team == game.Teams.Marines then
		message = string.lower(message)
		for i=1,#cChats do
			if message:find(cChats[i]) then
				local voiceline = script:FindFirstChild(message)
				if voiceline then
					debounce = true
					local vClone = voiceline:Clone()
					vClone.Parent = player.Character.Head
					vClone:Play()
					vClone.Ended:Wait()
					vClone:Remove()
					debounce = false
				end
			end
		end
	end
end

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

I am not that familiar with using string methods. I have tried looking at the strings page but I could barely understand most of it.

Mostly because even if it finds a sentence/word, you still make it find a child with the full message. If it finds it, can’t you just use cChats[i] instead of message for FindFirstChild?

Also Remove is deprecated, use Destroy instead

1 Like

This worked! Thank you. I just kind of like using :Remove() when it comes to clones.

1 Like