How to stop moving up only once?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TheAsker

I am making a 2d platformer. The player can jump higher by holding the jump button. The play stops moving up when the jump button is released, but the player can slow their jump by mashing the jump button. How can I stop this? This is the code.

extends KinematicBody2D

var motion = Vector2()
var airjump = 0.2
var airtime = 0.2
var cutjumpheight = 0
const MOE = 0.2
const CTIME = 0.2
const SPEED = 300
const GRAVITY = 60
const JUMPHEIGHT = -750
const UP = Vector2(0,-1)

#move right and left whenthe arrow keys are presed
func _physics_process(delta):
	motion.y += GRAVITY
	if Input.is_action_pressed("ui_right"):
		motion.x = SPEED
	elif Input.is_action_pressed("ui_left"):
		motion.x = -SPEED
	else:
		motion.x = 0
	
	#Timer to dimtermine if the player inputed the jump button recently
	airjump -= get_process_delta_time()
	if Input.is_action_just_pressed("ui_up"):
		airjump = CTIME
	#Timer to see if the player was on the floor recently
	airtime -= get_process_delta_time()
	if is_on_floor():
		airtime = MOE
	
	#Tells the game to jump
	if airtime > 0 && airjump > 0:
		motion.y = JUMPHEIGHT
	#makes the player stop moving up when jump is released
	if Input.is_action_just_released("ui_up") && motion.y < 0:
		motion.y = 0
	
	
	motion = move_and_slide(motion, UP)
	pass
:bust_in_silhouette: Reply From: guppy42

Basically just ignore new keypresses if the player is not on the floor