-- Connects the given collision function to the object's "Touched" event, but only if that object is a Part
-- Otherwise, it tries this function on all of the object's children

local function attachCollisionFunction(item, collisionFunction)

    if item:IsA("BasePart") then
        item.Touched:Connect(collisionFunction)
    else
        for _, child in ipairs(item:GetChildren()) do
            attachCollisionFunction(child, collisionFunction)
        end
    end
end
