If within If

How are your buttons and sensor connected? Post your code, like this:
HowToPostCode