Why doesn't it register?

So the idea of the code is, when i press “Space” and the object is hit on the right or the left by an object with tag “Wall” to be pushed in the oposite direction. But when it is hit on the left or right side the booleans don’t register that.

var sidePush : float = 4f;
var upPush : float = 2f;
var leftSide : boolean = false;
var rightSide : boolean = false;
var jumpKey : KeyCode;

function Update () {
    Debug.DrawLine(Vector3(transform.position.x - 0.5, transform.position.y, transform.position.z), Vector3(transform.position.x - 1.5, transform.position.y, transform.position.z), Color.red);
    Debug.DrawLine(Vector3(transform.position.x + 0.5, transform.position.y, transform.position.z), Vector3(transform.position.x + 1.5, transform.position.y, transform.position.z), Color.blue);
    
//Push to the right
    if(Input.GetKeyDown(jumpKey) && leftSide == true)
    {
        GetComponent.<Rigidbody>().velocity.x = sidePush;
        GetComponent.<Rigidbody>().velocity.y = upPush;
        leftSide = false;
    }
//Push to the left
    if(Input.GetKeyDown(jumpKey) && rightSide == true)
    {
        GetComponent.<Rigidbody>().velocity.x = -sidePush;
        GetComponent.<Rigidbody>().velocity.y = upPush;
        rightSide = false;
    }
}

function OnCollisionEnter (coli : Collision) {
    var hitRight : RaycastHit2D = Physics2D.Linecast(Vector2(transform.position.x + 0.5,transform.position.y), Vector2(transform.position.x + 1.5,transform.position.y));
    var hitLeft : RaycastHit2D = Physics2D.Linecast(Vector2(transform.position.x - 0.5,transform.position.y), Vector2(transform.position.x - 1.5,transform.position.y));

    //THE PROBLEM IS HERE SOMEWHERE!!!!!
    if(hitRight.collider != null && coli.gameObject.tag == "Wall")
    {
        rightSide = true;
    }
   
    else if(hitLeft.collider != null && coli.gameObject.tag == "Wall")
    {
        leftSide = true;
    }
}

function OnCollisionExit ()
{
    rightSide = false;
    leftSide = false;
}

You are using OnCollisionEnter which is 3D and then you use Physics2D.Linecast which is 2D. Are you really mixing 2D and 3D physics or should you be using OnCollisionEnter2D?

When i try to use this

function OnCollisionEnter (coli : Collision) {
    var hitRight : RaycastHit = Physics.Linecast(Vector3(transform.position.x + 0.5,transform.position.y,0), Vector3(transform.position.x + 1.5,transform.position.y,0));
    var hitLeft : RaycastHit = Physics.Linecast(Vector3(transform.position.x - 0.5,transform.position.y,0), Vector3(transform.position.x - 1.5,transform.position.y,0));
   
    if(hitRight.collider != null && coli.gameObject.tag == "Wall")
    {
        rightSide = true;
        Debug.Log("You hit: " + hitRight.transform);
    }
   
    else if(hitLeft.collider != null && coli.gameObject.tag == "Wall")
    {
        leftSide = true;
        Debug.Log("You hit: " + hitLeft.transform);
    }
}

It gives a error saying “Cannot convert “boolean” to “UnityEngine.RaycastHit””

I think Physics.Linecast returns a bool. If you want info about the hit, you need to include a HitInfo parameter. Have a look at: Unity - Scripting API: Physics.Linecast