Dynamic Jump causes infinite jump

Godot Ver:

4.6.2 Stable

Question:

Hello! I was working on creating a movement system and added a jump system that works depending on how long you hold the jump button for; and while I got that part to work, it also allows the player to jump infinitely (making it seem like they’re floating mid-air). I tried fixing this myself which is in the code below, while also making so that there is a variable for how many jumps the player can do in the air, but to no avail. Does anyone one a fix using the code below??

Thanks!

extends CharacterBody2D

@export var Acceleration := 5
@export var Max_Speed := 125
@export var Friction := 0.5
@export var Gravity := 980
@export var Jump_Force := 250
@export var jumps_available := 1

var input_direction := 0
var move_speed := 0.0
var jump_buffer := 0.0
var coyote_time := 0.0

func _physics_process(delta):
	jump_buffer -= 1 + delta
	coyote_time -= 1 + delta
	if is_on_floor():
		coyote_time = 15
	else:
		velocity.y += Gravity * delta
	if Input.is_action_just_pressed("Jump") and jumps_available > 0:
		jump_buffer = 30
		jumps_available -=1
		
		
	if coyote_time > 0 and jump_buffer > 0:
		velocity.y = -Jump_Force
		jump_buffer = 0
		coyote_time = 0
	if Input.is_action_just_released("Jump"):
		velocity.y = -Jump_Force * 0.1
	
		if velocity.y <= 0:
			jumps_available = 1
	
	input_direction = Input.get_axis("Left","Right")
	if input_direction:
		move_speed += Acceleration * input_direction
	else:
		move_speed *= Friction
	move_speed = clamp(move_speed, -Max_Speed, Max_Speed)
	
	velocity.x = move_speed
	
	move_and_slide()

If you release the jump button you will gain a jump, which doesn’t depend on touching the floor. Maybe you should reset jumps if is_on_floor() is true, like your coyote_time variable.