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

How do you find a part from a table?

I have a 10X10 grid of parts, labeled with letters and numbers, like battleship or chess. What I am trying to do is take a table like this

local middle = {'e5','e6','f5','f6'}
local square = {'d4','d5','d6','d7','e4','e7','f4','f7','g4','g5','g6','g7'}

and then make all the parts that are not in the table disappear. I am not sure how to check if the parts name is in the table. Thank you for reading!

1 answer

✓ Accepted answer
--tableContains returns true if the string in the partName parameter is in the table
--t: the table to examine
--partName: the string to look for
local function tableContains(t, partName)
	local result = false
	for i,v in ipairs(t) do
		if v == partName then
			result = true
			break
		end
	end
	return result
end

for i,v in ipairs(MyModel:GetChildren()) do
	if not tableContains(middle, v.Name) and not tableContains(square, v.Name) then
		v.Transparency = 1
	end
end

1 comment

0

Thank you! It seems to work great!

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