Allah the Exalted said: And to Thamud (people We sent) their brother Salih. He said: "0 my people! Worship Allah, you have no other Ilah (god) but Him (none has the right to be worshiped but Allah). Indeed there has come to you a clear sign (the miracle of the coming out of a huge she-camel from the midst of a rock) from your Lord. This she-camel of Allah is a sign unto you; so you leave her to graze in Allah's earth, and touch her not with harm, lest a painful torment should seize you. And remember when He made you successors after 'Ad (people) and gave you habitations in the land, you build for yourselves palaces in plains, and carve out homes in the mountains. So remember the graces (bestowed upon you) from Allah, and do not go about making mischief on the earth."
The leaders of those who were arrogant among his people said to those who were counted weak - to such of them as believed: "Know you that Salih is one sent from his Lord." They said: "We indeed believe in that with which he has been sent." Those who were arrogant said: "Verily, we disbelieve in that which you believe in.
So they killed the she-camel and insolently defied the Commandment of their Lord, and said: "0 Salih! Bring about your threats if you are indeed one of the Messengers (of Allah)." So the earthquake seized them, and they lay (dead), prostrate in their homes. Then he (Salih) turned from them, and said: "0 my people! I have indeed conveyed to you the Message of my Lord, and have given you good advice but you like not good advisers." Surah 7: 73-79
All were destroyed before they realized what was happening. As for the people who believed in the message of Salih , they were saved because they had left the place.