grounded and not grounded at the same time

i made a script to check for grounded

currentY = transform.position.y;
		if (currentY == lastY) {
						grounded = true;
			print ("grounded");
		} else if (currentY != lastY)
						grounded = false;
		print ("not grounded");
		lastY = currentY;

when i test it, it prints grounded and not grounded simultaneously when the player is not moving, whilst the player is falling it prints not grounded more but still prints grounded as well. what could be causing this?

…put in your curly brackets. Without the curly brackets an else if only takes the very next line. Hence “not grounded” would be printed every time.

if (currentY == lastY) {
    grounded = true;
    print ("grounded");
} else if (currentY != lastY) {
    grounded = false;
    print ("not grounded");
    lastY = currentY;
}