Crouching under blocks in a platforming game

Godot Version

Godot 4.7.2 Stable

Question

I am creating a mario-like platforming game. I want to include a crouch feature which I have already got simple code for. However, when crouching under a block, if you let go of crouch then you will get stuck and have to re crouch. This makes sense with my current code. Is there an easy way to detect when you uncrouch under a block? So that it can keep you crouching until you are out from underneath the block.

I wasn’t able to upload a video example as I am a new user.

I wasn’t sure if this would be considered help with Physics or Programming. Sorry for the bad video quality.

In my platformer game, I have a raycast just above the player that appears when they enter crouching state, and as long as there’s a wall above them (The raycast is only as long as the player would be when standing up), then I know I should keep the player in that state.