Adding Force to Rigidbody2D in C#

I’ve only recently started programming, so I hope this is an easy fix. Anyways, I started out with my script functioning in the 2D sections of unity. I originally could not get rigidbody2D.AddForce(x,y); to work, so as I test I moved it all over to 3D for rigidbody3D.AddForce(x,y,z); and it worked! At this point, I’m entirely unsure of what the problem is. Here is the portion of the script using this.

 //If player is moving and if player is not moving too fast;
 if (Input.GetButton ("Horizontal") ) {

    //Set horizontal movement;
    if(velocityTracker < velocityCap ){

    rigidbody2D.AddForce(speed * horizontal * Time.deltaTime * 100 * boostX, 0f);

    Debug.Log (rigidbody2D.velocity);
    
}
}

If you only changed the code to rigidbody3d and it worked, then this means that your gameobject has a rigidbody3d component, and you can’t use rigidbody2d commands.

In the unity editor, select your GameObject, and check which component it has (in the inspector). If it is a “rigidbody” component, then remove it, and then add a rigidbody2d component instead (under component → physics 2d → rigidbody 2d).