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
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.
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)