Check if variable is in a table (don't know how to explain)

I am making a 2048 type of project, and I have all of the valid numbers in a table and it will destroy the object if it is not a valid number. Here is script, I don’t really know how to explain without using script referance.

local Box = script.Parent
local Num = 2
local NS = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048}

if Num ~= NS then
Box:Destroy()
end

Thank you!

table.find() will be perfect

Alright, will try this. Thank you

I have no idea if I’m doing this correct, It runs either way. Tell me if I’m using it right

local Box = script.Parent
local Num = 2
local NS = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048}

if Num ~= table.find(NS, Num) then
print(Num)
Box:Destroy()
end

Ah, nevermind. I had to get rid of the Num ~= and that fixed it, Thank you!

local Box = script.Parent
local Num = 2
local NS = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048}

if table.find(NS, Num) then
    print(Num)
    Box:Destroy()
end

the if statement will run if it finds Num in the table
if you want it to do the opposite then do this

if not table.find(NS, Num) then
2 Likes

Yep, thank you for your help!!