Checking if a value is in a table

Basically i just want to check if a value equals to any value in a table. I’ll explain it a little better.

This is my script:

local tb = {"messagee", "messageee"}

local plr = game.Players.LocalPlayer

plr.Chatted:Connect(function(msg)
	local message = string.lower(msg)
	if message == #tb then
		print("Message is in the table")
	end
end)

It is not working though, i added prints into it and the error is in the if message == #tb then part, so if anyone could help me, i’d appreciate it very much.

I am not very used to using tables so that is why i am struggling with something that probably is very simple.

1 Like

local tb = {“messagee”, “messageee”}

local plr = game.Players.LocalPlayer

plr.Chatted:Connect(function(msg)
local message = string.lower(msg)
if tbl[message] then
print(“Message is in the table”)
end
end)

1 Like

You can simply use table.find.

local tb = {"messagee", "messageee"}

local plr = game.Players.LocalPlayer

plr.Chatted:Connect(function(msg)
	local message = string.lower(msg)
	if table.find(tb, message)
		print("Message is in the table")
	end
end)
10 Likes

Yeah i was thinking of using that, i just didn’t know how to it worked. Thanks!

For table.find, the first parameter is the table, the second one is the string. In this case the string we want to check is “message.”

2 Likes