Answer: Because the electrons present in the atoms of each metal have only certain allowed energy levels
Step-by-step explanation:
Differente metals emitting different colors of light is a situation related to the flame test.
This test is used to identify some inorganic chemical elements, by means of the emission of light by the phenomenon of atomic excitation by the increase in temperature.
In this sense, when an atom is excited, it means that it has left its ground state (in which each electron occupies its place in its orbit, around the nucleus), when this happens some electron jumps out of the orbit it occupied in its fundamental state to an outer orbit, further away from the nucleus and then return to the ground state, emitting in the form of light the energy received.
To understand it better:
An excited electron is an unstable electron, and when passing from one orbit to another, it produces light of a specific wavelength (color) that depends on the amount of energy the electron loses.
This is why different metals emit different colors of the light when heated.