How come this script only allows my object to jump once?

I’m trying to add jumping mechanics and I’ve tested this:

bool canJump = true;
public float jumpForce = 500;

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        jump();
    }
}

void jump()
{
    if (canJump)
    {
        canJump = true;
        GetComponent<Rigidbody>().AddForce(this.gameObject.transform.up * jumpForce);
    }
}

void OnCollisionEnter(Collision collidingObject)
{
    if (collidingObject.gameObject.layer == 8)
    {
        canJump = true;
    }
}

}

The only problem is I can only jump once, any idea on how I can fix this? And if you think something could improve this let me know! Thanks…

Please help its pretty urgent!

Just to clean your code a bit!
And since this code is working, you have to provide further information about what you script setup looks like. Are there any other scripts attachted to the GameObject?

 bool canJump = true;
 public float jumpForce = 500;

 void Update() {
     if (Input.GetKeyDown(KeyCode.Space)) {
         jump();
     }
 }

 void jump() {
     if (canJump) {
         GetComponent<Rigidbody>().AddForce(transform.up * jumpForce);
     }
 }

 void OnCollisionEnter(Collision collidingObject) {
     if (collidingObject.gameObject.layer == 8) {
         canJump = true;
     }
 }

void OnCollisionExit(Collision collision){
    if(collision.gameObject.layer == 8){
        canJump = false;
    }
}