What the title says. I want to compare the name of something to several strings to make sure it doesn’t match before firing, mainly so I don’t have to do
if v.Name ~= name and v.Name ~= name and v.Name ~= name and v.Name ~= name etc…
If you know the names you’re checking beforehand, you can create a table with the names in them then iterate over that table to compare each value in the table against whatever something’s name is.
local names = {"name1", "name2", "name3", "name4"}
local nameCheck = "name3"
for i, v in pairs(names) do
if v == nameCheck then
print(string.format("match! index: %d value: %s", i, v))
end
end
here is a simple solution that you should be able to understand:
local flag = true --a flag variable to test if it does
local listOfStrings = {"hi","bye","no"}
for _,String in pairs(listOfStrings)do
if v.Name == String then--checking if the name is equal to any one of the terms
flag = false--now our flag becomes false
end
end
if flag then
--only will run if v.Name is different from all the strings
end