Scrying on a creature with legendary resistance

My players recently decided that they would like to cast the Scry spell on a creature that has the Legendary Resistance trait.

Does this trait function outside of combat?

My major concern is that the creature wouldn’t necessarily know it was being scryed on in order to use the resistance to avoid it. In combat, a creature could see a (for example) fireball coming and decide to avoid it, but with no indicator at all that a spell was targeting the creature, it is less clear to me.