local function doFadeWipe(state)
  fadeWipe = celeste.FadeWipe(engine.Scene, state, nil)
  engine.Scene:Add(fadeWipe)
  fadeWipe.duration = 2
  fadeWipe.EndTimer = 1
end


function onBegin()

  if getFlag("enterelevator") then

    disablePause()
    disableMovement()
    waitUntilOnGround()
    walkTo(4801)
    wait(0.5)

    elevator = celeste.Mod.MaxHelpingHand.Entities.MoreCustomNPC.GetNPC("elevator")
    elevator:PlayAnimation("close")
    wait(1)

    doFadeWipe(false)
    wait(1.3)

    setFlag("finishtreehouse", false)
    setFlag("enterelevator", false)
    setFlag("inelevator")

  end

end