use a loop and run :IsDescendantOf(workspace) on each item until one of them satisfies that condition
Something like this
--returns the first instance in the table that is under workspace
local function inWorkspace(t: {Instance}): Instance?
for _, v in t do
if v:IsDescendantOf(workspace) then return v end
end
return nil
end
local tableParts = {"Part1", "Part2", "Part3"}
for i, part in pairs(workspace:GetChildren()) do
if table.find(tableParts, part.Name) then
— code here
end
end
that helped me, but I still with a question: IsDescendantOf would help if I could use to all values in the table at the same time
I want: If there is any of them (Part1, Part2 or Part3) the code will execute
I think your script i’ll use if on only 1 instance instead of all of them (Sorry if im wrong, but I want to understand it better if i’m wrong)
The function will return the first instance it finds in the table that is under workspace. If it doesn’t find any, it returns nil. You can change it to just return true and toss it into another if statement to do other things
For example, if you want to print out the table if anything inside of it is under workspace:
local function inWorkspace(t: {Instance}): boolean
for _, v in t do
if v:IsDescendantOf(workspace) then return true end
end
return false
end
local t = {workspace.Part1, workspace.Part2, workspace.Part3}
if inWorkspace(t) then
print(t)
end