How can I search through this table to find out if a player said any of these words?

Pretty much all I want is to search through the table to see if the player said any words that are inside the table then it’ll run my code.

	local table = {
				"No",
				"Yes",
				"Maybe"
			}
		elseif string.lower(message) == --table search to see if one of words was said
then 
			print("Kidnapped".. player.Name)
		end
local Words = {
	"No",
	"Yes",
	"Maybe"
}
game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message, Speaker)
		for _,v in Words do
			if v:lower():match(Message:lower()) then
				print("Kidnapped "..Player.Name)
				break
			end
		end
	end)
end)
1 Like

If you don’t want a loop you can use this. Since the strings in Words have their first letter capitalized, we take the message the player said, lower it, then capitalize the first letter;

local Words = {
	"No",
	"Yes",
	"Maybe"
}
game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message, Speaker)
		local Word = Message:lower()
		Word = string.gsub(Word, "^%l", function(letter) return string.upper(letter) end)
		if table.find(Words, Word) then
			print("found it again.")
		end
	end)
end)
1 Like

Thank you so much I used the for loop and adjusted my script a bit and now it works perfectly!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.