Why does Scotland compete separate from the UK in Commonwealth games but not the Olympics?

Cause there cheats ya would think if they compete in the comenwealth games under their own flag why carnt they in the Olympics