First at the jumpscare block (the block where the animatronic is considered ready to jumscare) place a dirt block below this block. This is important.
Name the armor stand “animatronic”
Make the door an iron door, forcing the player to control it with a lever. YOU WANT THIS. This is the source of the entire jump scare code. This also means the wall that the lever is on must be three blocks thick so redstone can go through it. The level should control the door(the door is simply decoration at this point). Make a redstone path inside the wall that goes up. This is best with slabs going like this to the roof of your build:
Once that is we will take out our command blocks. First create a repeating command block. DO NOT CONNECT THIS TO THE REDSTONE. The properties should be: Unconditional, always active, 0 tick delay. Then enter this code:
/execute @e [name= animatronic] ~ ~ ~ /testforblock ~ ~-2 ~ dirt
This command checks if the animatronic is at the jumpscare position.
Then place a conditional chain command block in front of it with the properties always active, conditional, 0 tick delay with no code.
Dont remove the command block because it doesn't have a code. It is simply there to send a signal when the animatronic is on the jumpscare block.
Now feed a comparator out of it. Now place two redstone dust away from the comparator and place another comparator. This is where your redstone from the lever takes place. Connect it to the side of the second comparator(place levers if needed). MAKE SURE THE SIGNAL STRENGTH IS AT 14 WHEN IT CONNECTS OR IT WILL NOT WORK. This will tell the game if the door is closed or not. Now place repeating command block with 0 tick delay, needs redstone, and unconditional and the following code:
/tp @p ~ ~ ~ facing armor_stand [name = animatronic]
This makes the player face the monster as it jumpscares you.
Place a chain command block with the properties unconditional, always active, 25 tick delay. This is the jumpscare command. You choose what to do with it.
Finally place a final chain command block in front of the other one with the properties of unconditional, always active, tick delay varies on how long you want the jumpscare to last. With the code: