Need Help with Movement Script

I made this little movement script, it’ for a basic 2D platformer but when I use it my “MotionX” Variable will not be set to 0 when I’m not pressing any keys. Please help!!

var motionX : float;

function Start () {

}

function Update () {

if(Input.GetKeyDown("left")) {

motionX = -10;
}

if(Input.GetKeyDown("right")) {

motionX = 10;
}

if(Input.GetKeyUp("right") && Input.GetKeyUp("left")) {

motionX = 0;



}
rigidbody2D.velocity = (Vector2(motionX,0));
}

Sorry for being a bit newbie. :confused:

GetKeyUp only triggers on the single frame the key went up, so wont go to zero unless both are release at the same time
If you instead use GetKey(“…”) it will trigger every frame that the key is held