What will happen to the righteous people who are still on the earth when God cleanses the earth by fire.
At the coming of Christ, the wicked will be burned as stubble:
“For the hour is nigh and the day soon at hand when the earth is ripe; and all the proud and they that do wickedly shall be as stubble; and I will burn them up, saith the Lord of Hosts, that wickedness shall not be upon the earth” (D&C 29:9).
The righteous dead will be resurrected:
“But before the arm of the Lord shall fall, an angel shall sound his trump, and the saints that have slept shall come forth to meet me in the cloud” (D&C 45:45).
And the righteous who are still alive will be lifted off the earth to meet the resurrected host:
“For the Lord himself shall descend from heaven with a shout, …Then we which are alive and remain shall be caught up together with them in the clouds, to meet the Lord in the air” (1 Thessalonians 4:16-17)
President Joseph Fielding Smith had this to say regarding the subject:
D&C 29:9. The Wicked Shall be Burned as Stubble
Is this passage figurative, or will the wicked really burn? President Joseph Fielding Smith said: “It is not a figure of speech that is meaningless, or one not to be taken literally when the Lord speaks of the burning. All through the scriptures we have the word of the Lord that at his coming the wicked and the rebellious will be as stubble and will be consumed. Isaiah has so prophesied. … Surely the words of the Lord are not to be received lightly or considered meaningless.” (Church History and Modern Revelation, 1:238.)
Christ is a glorified, celestial being, and the glory of such beings is comparable to that of the sun (see D&C 76:70). The presence of Christ when He comes in His glory will be as a consuming fire. The mountains will flow down at His presence, the elements will melt with fervent heat, and the waters will boil. Even the sun will hide its face in shame. (See Hebrews 12:29; D&C 133:40–44, 49.) The scriptures also talk about the time when “devouring fire” will be poured out upon the wicked (D&C 29:21; see also D&C 35:14; 1 Nephi 22:17, 23; Ezekiel 38:22;39:6).