using optical gates to count how many peapole are in a room with(b83609)

The delays prevent your code from working properly.

Answer to yourself:

  • How many sensors can be covered by one person?
  • How do the signals change if one person goes through, goes back, a second person enters...

What you need is a state machine, with states like
empty, one_in, one_through, one_back, two_in

Then determine whether changes in the sensor values allow to determine the new state of that machine, and to count the persons properly.