How to select a group instead of a singular part?

This code works but only if the part is just one part and I want to know how to change it where I can select a group or a whole rig instead of a part.
local Part = game.Workspace:FindFirstChild(“Part”)

local Humanoid = script.Parent:FindFirstChild(“Humanoid”)

local function onHumanoidDeath()
if Humanoid.Health <= 0 then
Humanoid.Parent:Destroy() – Destroy the character
Part.CanCollide = true --// Make that you cannot walk through the part
Part.Transparency = 1 --// Makes the part transparent.
end

end

Humanoid.Died:Once(onHumanoidDeath)

Use :GetChildren() and for loops

Example:

local Holder = --// Path to the rig or group

local Humanoid = script.Parent:FindFirstChild(“Humanoid”)

local function onHumanoidDeath()
    if Humanoid.Health <= 0 then
        Humanoid.Parent:Destroy() – Destroy the character
        
        for i,v in pairs(Holder:GetChildren()) do 
            v.CanCollide = true 
            v.Transparency = 1
        end
    end

end

Humanoid.Died:Once(onHumanoidDeath)

if the group/rig has not only parts then you will need to check if its a part

        for i,v in pairs(Holder:GetChildren()) do 
            if v:IsA("Part") or v:IsA("BasePart") then 
                v.CanCollide = true 
                v.Transparency = 1
            end
        end
1 Like

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