How can I prevent the character from jumping if there is an object above them?

I’m creating this first person game, the character can crouch and jump, when you’re crouching and there’s an object above you, if you try to uncrouch nothing happens, I do this using a raycast upwards to check if hits something, now the problem is i’m using the exact same method with jumping but it’s not working, if you jump and there’s an object above you, the character clips through and gets stuck. Idk if the problem is in the code or the player jumps too fast the object doesn’t recognise it and the player gets stuck.Here’s my code.

private void HandleJumping()
    {
        if (shouldJump && !Physics.Raycast(characterController.transform.position, Vector3.up, 0.5f))
        {
            moveDirection.y = jumpForce;
        }            
    }
private void HandleCrouching()
    {
        if (shouldCrouch)
            StartCoroutine(CrouchStand());
        if (isCrouching && shouldJump && !Physics.Raycast(characterController.transform.position, Vector3.up, 0.5f))
            BreakCrouchOnJump();
    }
    private void BreakCrouchOnJump()
    {
        characterController.height = standingHeight;
        characterController.center = standingCenter;
        isCrouching = false;
    }
    private IEnumerator CrouchStand()
    {
        if (isCrouching && Physics.Raycast(playerCamera.transform.position, Vector3.up, 0.5f))
            yield break;

        duringCrouchingAnimation = true;

        float timeElapsed = 0;
        float targetHeight = isCrouching ? standingHeight : crouchingHeight;
        float currentHeight = characterController.height;
        Vector3 targetCenter = isCrouching ? standingCenter : crouchingCenter;
        Vector3 currentCenter = characterController.center;

        while (timeElapsed < timeToCrouch)
        {
            characterController.height = Mathf.Lerp(currentHeight, targetHeight, timeElapsed / timeToCrouch);
            characterController.center = Vector3.Lerp(currentCenter, targetCenter, timeElapsed / timeToCrouch);
            timeElapsed += Time.deltaTime;
            yield return null;
        }

        characterController.height = targetHeight;
        characterController.center = targetCenter;

        isCrouching = !isCrouching;

        duringCrouchingAnimation = false;
    }

Check if there is an object above them, use a ray or other collision detection solution, then you can assign it to a bool like bool isObjectAbovePlayer; you set the result of the collision detection to the bool then in your jump you check the bool, if(isObjectAbovePlayer) return; or whatever…