run script something wrong ?

Hi am i am trying to make my char run when shift held down… it works fine if i remove the jump part but … It’s like i can’t have more then 2 if statements at same time. cus then the third don’t work . Is there some max ? tryed changing and make it an else but no luck.

var speed = 6.0;
var walkSpeed = 6;
var jumpSpeed = 8.0;
var gravity = 20.0;
var runSpeed = 15;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;

// lots of vars not every one is in in use atm, but should not matter


function FixedUpdate() {
	if (grounded) {
		// We are grounded, so recalculate movedirection directly from axes
		moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
		moveDirection = transform.TransformDirection(moveDirection);
		moveDirection *= speed;
		
		
		// i am jumping (problem from here to )
		if (Input.GetKeyDown (KeyCode.Space)) {
		
		print("jump");
			moveDirection.y = jumpSpeed;
			
			
			
			// i am running 
		if(Input.GetKey(KeyCode.LeftShift)){
		
		moveDirection *= runSpeed;
		print ("You are running mfo");
		// (problem end)
	
		}


		}
	}

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

@script RequireComponent(CharacterController)

That’s because you’re nesting the if’s.

What you’re code is saying is: “If we are grounded AND Space is pressed AND left shift is down, run faster”

if (grounded) {
    if (jumping) {
        if (running) {

        }
    }
}

Instead, you need to separate the running and jumping.

if (grounded) {
    if (jumping) {

    }

    if (running) {

    }
}

Indenting your code makes it easier to see these sorts of problems.

found the problem

i had the if statement open where jump opens and then if run could never happen

You where fast… Ye you found the same error and it worked fine when i took away the nest…

Thanks for quick response !