How to make GetPartsInPart work in Folder

Hi,

I have one problem,I want to get parts in parts in one folder becuase GetPartsInPart only works in workspace not in Folder.

I also wanna ask if someone could explain me it aswell because I do not really understand this function.I also tried using GetTouchingParts but I dont want that I want to get parts in part just so it works in Folder

Thanks a lot!

1 Like

What do you mean?? GetPartsInPart returns any part that is in the geometry bounds of the provided part. You check if a part in the array that is returned is a children of the said folder.

1 Like

GetPartsInPart basically just grabs all the parts that are touching or are inside of the target part.

The code I wrote has a function that should filter out all the parts that are not in the folder.

The code

This should work if I understood what you said correctly. I tried to explain what everything does.
I wrote this on mobile so the code looks a bit funky.

local CheckFolder = Folder --The folder to check in
local PartsInPart = workspace:GetPartsInPart(Part)

local function GetPartsInFolder(Parts, Folder)
--The end list of parts that were in the folder
local PartsInFolder = {}

--Everything contained in the folder, this is used to check if the parts are in the folder.
local FolderChildren = Folder:GetDescendants()

for _, Part in PartsInPart do --Loop through all the parts
if table.find(FolderChildren, Part) then
--If the part is found inside the folder, add it to the final list
table.insert(PartsInFolder, Part)
end
end

return PartsInFolder --Return the final list of parts
end

local Result = GetPartsInFolder(PartsInPart, CheckFolder)
print(Result)

Hope this helps.

2 Likes

Thanks for the code! It really helped me

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.