Here's why:
* Doppler Effect: Just like the sound of a siren changes pitch as it moves towards or away from you, the light from a star changes frequency as it moves towards or away from us. This is known as the Doppler Effect.
* Blueshift: When a star is moving towards us, the light waves it emits get compressed, causing the wavelengths to shift towards the blue end of the electromagnetic spectrum. This is known as blueshift.
* Redshift: Conversely, when a star is moving away from us, the light waves get stretched, causing the wavelengths to shift towards the red end of the spectrum (redshift).
So, observing the blueshift in a star's light tells us that it's moving towards us, while redshift tells us it's moving away.