Speed check issue

I am trying to switch between two modes / flight and taxi for an airplane. The problem is I don’t want a special key for it. Once the plane speed is over, say, 10, flight mode kicks off. Then, when I return to ground and speed down, once the speed is smaller than 10 the taxi mode should be enabled. The script I made does just that. Only once I complete the routine once - taxi - flight - taxi again - I cannot take off once more. The second it reaches speed 10, it hicks up and resets the speed to zero. I noticed this also happens sometimes from the start, but it manages to get over that moment and take off. Any help is appreciated, thanks!

var speed = rigidbody.velocity.magnitude * 2.237;
Debug.Log("speed" + speed);
if (speed >= 10 && !toggleTaxi) {
    toggleTaxi = !toggleTaxi;
    taxiOn();       
}
else if (speed <= 10 && toggleTaxi) {
    toggleTaxi = !toggleTaxi;
    taxiOff();       
}

The rigidbody should not reduce its velocity to 0, unless it collides with something when exiting taxi mode. Check the taxiOff function to see if something may be causing this - maybe a sudden direction change, or whatever.

Anyway, I would change the logic a little, adding some hysteresis to the taxi limit: have a higher speed to exit taxi mode, and a lower limit to reenter it - this would ensure that small variations in speed could not exit taxi mode in one update and reenter it in the next:

    ...
    if (toggleTaxi && speed > 12){ // higher limit to enter flight mode
      toggleTaxi = false;
      taxiOff();
    } else if (!toggleTaxi && speed < 9){ // lower limit to enter taxi mode
      toggleTaxi = true;
      taxiOn();
    }

In your current code, any small reduction in velocity when entering flight mode could make it reenter taxi mode next time the code is executed.