Jump Function Not Working With Character Controller

I’ve been working on a new game with a character controlled by a CharacterController.

I followed Unity’s tutorial, but it doesn’t work at all. My gravity works, but my character won’t jump when I want it to. It sometimes jumps when I hit space, and sometimes not.

void Jump()
{

    if (character.isGrounded)
    {
        velocity.y = 0; 
    }

    if(Input.GetKeyDown(KeyCode.Space) && character.isGrounded)
    {
        velocity.y += Mathf.Sqrt(jumpForce* gravity * 3); 
      
        
    }
    
   

    if(character.isGrounded == false)
    {
      velocity.y -= gravity * Time.deltaTime;
    }
    
    character.Move(velocity *Time.deltaTime);

}