[SOLVED] How to set cancollide off to all childs in a folder?

the title is self-explanatory, i wanna set cancollide off to all childs in a folder of workspace, i know how to set cancollide off for 2 childs but not for all of a folder(using PhysicsService)

for _, Child in pairs(workspace.Folder:GetChildren()) do
	Child.CanCollide = false
end
1 Like

you can use loop

local Folder = game.Workspace["FOLDER HERE"] -- You said folder in da workspace

for _, Object in pairs(Folder:GetChildren()) do
	Object.CanCollide = false	
end
1 Like

those are setting the child collisions off, i still want it to collide with other objects besides the descendants of the folder

for _, Child in pairs(workspace.FolderName:GetDescendants()) do
    if Child:IsA("BasePart") or Child:IsA("Part") or Child:IsA("MeshPart") then
        Child.Touched:Connect(function(hit)
            if hit.Parent ~= workspace.FolderName then
                Child.CanCollide = false
             else
                Child.CanCollide = true
            end
        end
    end
end

Edit: I apologize if there’s anything wrong in my code, I wrote this in Visual Studio Code in the middle of class.

1 Like

You’re probably looking for Collison groups:

https://developer.roblox.com/en-us/articles/Collision-Filtering

2 Likes
local Folder = workspace.Folder

local function SetCollisions(Bool)
	for _, Child in ipairs(Folder:GetDescendants()) do
		if Child:IsA("BasePart") then
			Child.CanCollide = Bool
		end
	end
end

SetCollisions(true) --enable collisions
SetCollisions(false) --disable collisions

“BasePart” is the base class for “Part” and “MeshPart” instances so you need only check if the instance is a member of the “BasePart” class.

2 Likes

Oh, thank you. Didn’t know that.

1 Like