Allah the Exalted said: And to Thamud (people We sent) their brother Salih. He said: "O 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: "O 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: "O 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.
Related Quran Ayaaths of this Hadith.
Surah 7 : Ayah 73 Surah 7 : Ayah 75 Surah 7 : Ayah 79 Surah 11 : Ayah 61 Surah 11 : Ayah 62 Surah 11 : Ayah 65 Surah 11 : Ayah 66 Surah 11 : Ayah 89 Surah 26 : Ayah 142 Surah 26 : Ayah 158 Surah 54 : Ayah 27 Surah 27 : Ayah 45 Surah 27 : Ayah 46"When a person dies, his works end, except for three: ongoing charity, knowledge that is benefited from, and a righteous child who prays for him."
Prophet Mohammed (PBUH)
"The best of what a man leaves behind are three: a righteous child who supplicates for him, ongoing charity the reward of which reaches him, and knowledge that is acted upon after him."
Sunan Ibn Mājah
"Every day two angels come down from Heaven and one of them says, 'O Allah! Compensate every person who spends in Your Cause,' and the other (angel) says, 'O Allah! Destroy every miser.'"
Sahih Bukhari