I’ve been trying for a while now to change a piece of code to allow movement in the air while my character is jumping. I’ve tried adjusting the flags and a few other pieces of code but usually my character floats after jumping and is able to move around in the air or other issues.

if(grounded) {
		moveDirection = new Vector3((Input.GetMouseButton(1) ? Input.GetAxis("Horizontal") : 0),0,Input.GetAxis("Vertical"));
	}


//Apply gravity
	moveDirection.y -= gravity * Time.deltaTime;
	
	//Move controller
	var controller:CharacterController = GetComponent(CharacterController);
	var flags = controller.Move(moveDirection * Time.deltaTime);
	grounded = (flags & CollisionFlags.Below) != 0;


@script RequireComponent(CharacterController)

Here I rewrote somethings but I think this does what you want.

function Update()
{
    moveDirection = new Vector3((Input.GetMouseButton(1) ? Input.GetAxis("Horizontal") : 0),0,Input.GetAxis("Vertical"));
    moveDirection = transform.TransformDirection(moveDirection);
    moveDirection *= isWalking ? walkSpeed : runSpeed;
 
    moveStatus = "idle";
    if(moveDirection != Vector3.zero)
    {
         moveStatus = isWalking ? "walking" : "running";
    }
    
    if (grounded && Input.GetKeyDown(KeyCode.Space)) 
    {
         gravity = jumpSpeed;
    }
 
    // Allow turning at anytime. Keep the character facing in the same direction as the Camera if the right mouse button is down.
    if(Input.GetMouseButton(1)) {
       transform.rotation = Quaternion.Euler(0,Camera.main.transform.eulerAngles.y,0);
    } else {
       transform.Rotate(0,Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime, 0);
 
    }
    gravity += Physics.gravity.y * Time.deltaTime;
    //Apply gravity
    moveDirection.y = gravity;

    //Move controller
    var controller:CharacterController = GetComponent(CharacterController);
    var flags = controller.Move(moveDirection * Time.deltaTime);
    grounded = (flags & CollisionFlags.Below) != 0;
}

Changing the y vector component can be a bit weird cause you TrasformDirection it and that can mess things up also I made gravity negative and then added it. Its just my preference but you can change it back to having it be positive and subtract it.

Somethings to keep in mind:

Adding (or subtracting) gravity every frame will adventually lead to a really big force pushing you down if you never jump. So jumping cancels gravity out and adds a force upward but if you never jump gravity will continually grow and you will fall faster as the game progresses (if you never jump). Jumping sort of resets this effect.

Also it is weird that every frame you GetComponent(CharacterController). You really only need to do that once. Its just redundant otherwise.

CharacterController has a variable isGrounded that you can use to do what your grounded variable does. Just a heads up.

You should look at the part of the code that actually changes your character’s position when they are on the ground. Figure out what conditions need to apply in order for that translation to happen, and then, extend the “if” statement that figures out if it can make an on-ground move with an “else” statement that moves your character while in there air.

Sorry if that’s a little vague, but you’ll need to put up the code that actually moves the character to receive more detailed advice.