Answer:
The electrons are exposed to thermal energy/heat causing the excitation of the electron that is the electron in the outer orbital get absorbed and bounce to higher energy level.
Under the spectroscope, omitted wavelengths are seen with bright colors. For instance, light with longer wavelength appears red and light with shorter wavelength appear purple.
So, therefore, different metals will produce different wavelengths of light that are giving off a characteristic color of light.
Comparing the position of the colored light helps in the identification of substances.