"If" statement and LEDs not working correctly

If 5V is on pin8 it will be true. If nothing is on pin8 it will be floating about and may register anything at all.

Get a pull-down resistor.

Steve