How to make something visible only through a doorway?

can you give me an example of how you did it? I’m struggling to make it work