Gen 6:6 And it repented the Lord that he had made man on the earth, and it grieved him at his heart.
7 And the Lord said, I will destroy man whom I have created from the face of the earth; both man, and beast, and the creeping thing, and the fowls of the air; for it repenteth me that I have made them.
8 But Noah found grace in the eyes of the Lord.
9 These are the generations of Noah: Noah was a just man and perfect in his generations, and Noah walked with God.

Noah received the covenant of Christ from his ancestors. In particular, Noah heard the covenant from Methuselah, who lived with Adam.

Gen 5:25 And Methuselah lived an hundred eighty and seven years, and begat Lamech.
26 And Methuselah lived after he begat Lamech seven hundred eighty and two years, and begat sons and daughters:
27 And all the days of Methuselah were nine hundred sixty and nine years: and he died.
28 And Lamech lived an hundred eighty and two years, and begat a son:
29 And he called his name Noah, saying, This same shall comfort us concerning our work and toil of our hands, because of the ground which the Lord hath cursed.

Gen 3:15 And I will put enmity between thee and the woman, and between thy seed and her seed; it shall bruise thy head, and thou shalt bruise his heel.

Methuselah lived with Adam for 243 years and received the covenant of Christ, and Noah lived with Methuselah for 600 years and received the covenant of Christ.

Jud 1:11 Woe unto them! for they have gone in the way of Cain, and ran greedily after the error of Balaam for reward, and perished in the gainsaying of Core.

Holding on to the covenant of Christ, Abel believed in Christ, the Lamb of God who would die for our sins, and offered a sacrifice to God, but Cain did not. Also, almost everyone followed the way of Cain.

Noah was the only one who understood and believed in Christ. No one believed in the covenant of Christ. Even his brothers who heard the covenant of Christ with Noah did not believe the covenant of Christ. So everyone, except Noah’s family, died in the flood. Noah, the only one who believed in the covenant of Christ, was the righteous.