How do I make speech activated events?

Hi, how do I make the script detect certain phrases that I say in the chat then connects it to certain functions? Which services do I need to get and how do I make it detect the phrases. A nice code example would be good.

game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(raw_msg)
local msg = raw_msg:lower()

local trigger = {"Your phrase"}
local chatwords = msg:split(" ")
		
		local function contains(list, x)
			for _,v in pairs(list) do
				if v:lower() == x:lower() then
					return true
				end
			end
			return false
		end
		
		for i, chatwords in pairs(chatwords) do
			local doesContain = contains(trigger, chatwords)
			if doesContain == true then
				--function here
			end
		end
	end)
end)
1 Like

Oh i forgot to say that the script must be in ServerScriptService and it has to be a normal script.

How do I approach the table if i wanna have multiple trigger words?

local trigger = {"phrase", "phrase"}

I hope this helped you!

Sure did, thank you kind sir. Catch this solution.