Stopping a task and holding motors

I’m new to VCS, and this might be a pretty basic question, but I was wondering how I could stop a task. Right now, I have something that looks like this:


int capdrive()
{
    Leftdrivefront.spin(vex::directionType::fwd, Controller.Axis3.value(), vex::velocityUnits::pct);
    Leftdriveback.spin(vex::directionType::fwd, Controller.Axis3.value(), vex::velocityUnits::pct); 
    Rightdrivefront.spin(vex::directionType::fwd, Controller.Axis2.value(), vex::velocityUnits::pct);
    Rightdriveback.spin(vex::directionType::fwd, Controller.Axis2.value(), vex::velocityUnits::pct);
}

int main()
{
    while(1)
    {
            vex::task drive(balldrive);

            if(Controller.ButtonR2.pressing()) 
            { 
                drive.stop();
                Rightdriveback.stop(vex::brakeType::hold);
                Rightdrivefront.stop(vex::brakeType::hold);
                Leftdriveback.stop(vex::brakeType::hold);
                Leftdrivefront.stop(vex::brakeType::hold);
            }

    }
}

The problem that I’m having is that the drive task won’t really stop, and since the drive code hasn’t stopped, the motors aren’t holding. How would I solve this?

How about putting the check for ButtonR2 inside of capdrive/balldrive (you’ve named it two different things). If you press the button, the motors hold, otherwise you send stick values to the motors.