Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

If all table values are not equal to?

Basically my script looks like this right now:

local foundpart = "x"

local parts = {
	"a",
	"b",
	"c",
	"d",
	"e",
}

for i = 1, #parts do
	if parts[i] ~= foundpart then
		print("not found")
	end
end

But this script will print "not found" 5 times, I want it to just print it once.

If I use break or return it will not check all the strings in the 'parts' variable.

1 comment

0

use debounce?

1 answer

You can use a dictionary instead.

local foundpart = "x"

local parts = {
   ["a"] = true,
   ["b"] = true,
   ["c"] = true,
   ["d"] = true,
   ["e"] = true,
}

if not parts[foundpart] then 
	print ( "not found")
end

or table.find()

local foundpart = "x"

local parts = {
   "a",
   "b",
   "c",
   "d",
   "e",
}

if not table.find(parts, foundpart) then 
	print ( "not found")
end

This discussion is preserved as it was. New answers, comments, and votes are closed.