Trying to stop my 2D platformer character from moving while crouching

Godot Version

4.3

Question

I have been trying to stop my character from moving while crouching, but it keeps moving if one crouches while moving , and I don’t understand why.

func handle_horizontal_movement(body:CharacterBody2D,direction:float) -> void:
	var velocity_change_speed: float= 0.0
	if body.is_on_floor():
		velocity_change_speed = ground_accel_speed if direction !=0 else ground_decel_speed
		if Input.is_action_pressed("Down") or Input.is_action_just_pressed("Down"):
			ground_accel_speed = 0
		else:
			ground_accel_speed = 150.0
	else:
		velocity_change_speed= air_accel_speed if direction !=0 else air_decel_speed
	
	body.velocity.x = move_toward(body.velocity.x, direction * speed, velocity_change_speed)

You made velocity_change_speed equal to ground_accel_speed before you checked for the down input and changed the ground_accel_speed. It would have to be after you changed it.