Elevator that moves one level and stays until you exit and enter volume at second level

I’ve been looking at tutorials and videos on how to make a simple elevator that inevitably does one of two things:

  1. it goes up, pauses, then returns back down or
  2. it goes up and stands still

How do I make an elevator that goes up once you enter its trigger volume and goes down once you exit the elevator and re-enter it at its new location?

Create three trigger volumes:

  1. One for the elevator
  2. One for the “upper floor” in front of the elevator
  3. One for the “lower floor” in front of the elevator

In the elvator, calculate a “desired location” as either “upper” or “lower” floor locations.
Also have a “newly set” flag that you default to false.
Each time any of the three volumes have a player enter or leave, you do the following:

  • If player is in zero, or more than one, volume, do nothing
  • If player is in “upper floor” volume, set the “desired location” to “upper floor” and set “newly set” to true
  • If player is in “lower floor” volume, set the “desired location” to “lower floor” and set “newly set” to true
  • If player is in the “elevator” volume, and the “Newly set” flag is true, then set the “newly set” flag to false, and set the elevator “desired location” to the one it’s currently not at (if it’s lower, make it upper, and vice versa.)

Inside tick, if the elevator is not at its desired location, make it move a small amount towards the desired location.