The distance from Earth to the Sun is about 149.6 million kilometers (93 million miles). It takes light from the Sun about 8 minutes and 20 seconds to reach Earth.
The distance from Earth to the nearest star, Proxima Centauri, is about 4.22 light-years away. This means that it takes light from Proxima Centauri about 4.22 years to reach Earth.
Gamma rays from an exploding star would reach Earth in the same amount of time as it would take light to travel from the star to Earth. If the exploding star was in our solar system, the gamma rays would reach Earth in a matter of seconds or minutes. If the exploding star was in a neighboring star system, the gamma rays would reach Earth in a matter of years. If the exploding star was in a distant galaxy, the gamma rays would reach Earth in a matter of millions or billions of years.