How to check if Part.Name is in an array?

Let’s say our part was name “Roblox”. And let’s say we made an array that looks like this:

local Games = {
    "Roblox",
    "Fortnite",
    "Valorant",
    "Apex"
}

How do we make an if statement to print out “This game is cool” if it was in the array and it’s a part’s name?

This is where you would use table.find which is a function that accepts two arguments: the table to look through and the value to look for in the table. The function returns the index of the value in the table if it is found, otherwise it will return nil:

local tbl = {"a", "b", "c"}

if table.find(tbl, "c") then
    print("c was found in the table") -- this will print
end

if table.find(tbl, "r") then
    print("r was found in the table") -- this will not print
end
1 Like