Finding a child with name from a list

i can’t seem to find a topic about this.
how do you find a child that has a name which exists on a list inside a module?
i’ve required the module and referenced the list but i’m not sure what to do from here.

Do you mean something like this?

--Module
local list = {
	"Dave";
	"Sam";
	"Emily";
	"Olive"
}

return list


--Server Script

local list = require(script.ModuleScript)
print(list[1]) -- Dave

Or

--Module
local list = {
	["Family1"] = {
		Dad = "Dave";
		Child = "Erik";
	};

	
}

return list



--Script
local list = require(script.ModuleScript)
print(list.Family1.Child) -- Erik

I might be confused a bit

my explanation might’ve been bad, sorry

what i mean is something more like

--Module

local list = {
	"Dave";
	"Sam";
	"Emily";
	"Olive"
}

return list

--Server Script

local model = -- (a model, with children)
local list = require(script.ModuleScript)
-- here i want to check if any of the children inside of the model have a name
-- which is on the list

Oh sure, you could do :

if table.find(list,model.Name) then
end

[table.find only works with arrays, so in this case it would work nice]


--Module
local list = {
	"Dave"
}

return list

--Script
local list = require(script.ModuleScript)


if table.find(list,"Dave") then
	print("Dave was found") -- prints
end

Or, if you have a table containing children, you could do:

local model 
for i,child in pairs(model:GetChildren()) do
    if table.find(list,child.Name) then
    end
end
3 Likes

well damn. your suggestion didn’t directly fix it but it sure as hell helped. you gave me a idea which i should’ve considered sooner, before posting on the devforum. thank you so much.

1 Like