How to use if with tables

  1. What do you want to achieve?
    Be able to check stuff in a table.

  2. What is the issue?
    I Can’t or Don’t know how to

  3. What solutions have you tried so far?
    I searched in the dev forum, I mean i tried at least but I couldn’t find any

local Table = {"Oxygen", "Nitrogen"}
if script.Parent.Value == Table then
	print(1)
end

The code is in a while loop.

You can get the index of a value.

For example, Oxygen is the first value so you can say in code Table[1]

local Table = {"Oxygen", "Nitrogen"}
if script.Parent.Value == Table[1] then
	print(1)
end

yeah but the parent’s value cant be nitrogen too

You can then use a for loop.

local Table = {"Oxygen", "Nitrogen"}

for i = 1, #Table do
	if script.Parent.Value == Table[i] then
		print(1)
	end
end
1 Like

Use table.find:

if table.find(Table, script.Parent.Value) then
4 Likes

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