I can’t see any evidence of you using a state machine in this code. That is the whole point here. A state machine would have a totally different structure. The top level is the loop function. Here you look to see if a task is due by compairing the current time with the time the task should be run, then when the time is right you call the function that does that task. You have two tasks, moving the servo and detecting people.
The moving the servo is simple as it only has one state, you enter it and the servo is moved one fixed small amount. The last thing that function does is to set the variable that determines when that task runs again. This time will be a function of the number of people in the room, you can use a map function call to give you a number that changes with the number of people.
The counting people is more complex, that has a number of states and you should use a state variable to keep track of what to do next. So the counting people task would first look for a breaking beam, then set when to look at the beam next, this is the equivalent of your delay, because no further progress is made until that time expires. But the time is used by the moving servo task. Then when you detect the beam is not broken, look for the other beam, this is the next stage or state of that task. Finally a delay, that is don’t do that task for a bit, and finally the increment of the number of people. The state variable lets you keep track of where you are with that task.