You can run away while keeping the door closed, once the animatronic hit the door they won't enter, below the comments there is a guide on how to beat night 4 made by xxtrowawayxx which I found super interesting