Jumping sometimes doesn't work

I’m trying to do a simple project where the character moves forward all the game and jumps when I press Space. Most of the time the character does jump, but sometimes he won’t. Please help me fix the problem. I’m a very beginner

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMotor : MonoBehaviour
private CharacterController controller;
private Vector3 moveVector;
private Vector3 moveDirection;
public float jumpForce;
public float GravityScale;

public float speed = 5.0f;

// Use this for initialization
void Start () {
    controller = GetComponent<CharacterController> ();

// Update is called once per frame
void Update () {

    if (controller.isGrounded)
        if (Input.GetButtonDown("Jump"))
            moveDirection.y = jumpForce;

    moveDirection.y = moveDirection.y + (Physics.gravity.y * Time.deltaTime);
    controller.Move(moveDirection * Time.deltaTime);

    controller.Move ((Vector3.forward * speed) * Time.deltaTime);


Hi, I’m having the same problem here but I think it has something to do with “Input.GetButtonDown” which only triggers once per frame, have you tried “Input.GetButton” instead?

I know this is pretty old but i’m having the same problem and would be glad if someone found the answer to this!