isGrounded is always false, even with gravity, how do you fix that?

How do I make it not be false all the time, i’ve seen some other people talking that its gravity’s vault, but i do already have it implemented velocity.y += gravity * Time.deltaTime;

Here’s the code, only isGrounded isn’t working, is there something wrong with the code, or the object that im walking on?

using UnityEngine;

namespace Praktyki.Player
    public class Movement : MonoBehaviour
        CharacterController controller;

        public float speed = 6f;
        public float gravity = -40f;
        public float jumpHeight = 3f;

        public Transform groundCheck;
        public float groundDistance = 0.4f;
        public LayerMask groundMask;

        Vector3 velocity;
        bool isGrounded;

        void Start ()
            controller = gameObject.GetComponent<CharacterController>();

        void Update ()
            isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

            float x = Input.GetAxis("Horizontal");
            float z = Input.GetAxis("Vertical");

            Vector3 move = transform.right * x + transform.forward * z;

            controller.Move(move * speed * Time.deltaTime);

            if (Input.GetButtonDown("Jump"))
                velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);

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

            if (Input.GetKey("left shift")) speed = 12f;
            else speed = 6f;

@krzygogogo use character controller ground detector instead:

CharacterController controller;
if( controller.isgrounded )
    //do something