"Thou shalt not bow down thyself unto them, nor serve them: for I the LORD thy God am a jealous God, visiting the iniquity of the fathers upon the children unto the third and fourth generation of them that hate me." (Deuteronomy 5:9)
This seemingly unwarranted penalty imposed on the innocent grandchildren of the idolater cannot possibly negate the later promise of God through the prophet Ezekiel: "The soul that sinneth, it shall die. The son shall not bear the iniquity of the father, neither shall the father bear the iniquity of the son: the righteousness of the righteous shall be upon him, and the wickedness of the wicked shall be upon him" (Ezekiel 18:20).
And certainly it cannot obviate the clear promise of Christ Himself in the last chapter of the Bible: "Let him that is athirst come. And whosoever will, let him take the water of life freely" (Revelation 22:17). Anyone who desires to do so may accept the Lord's gracious offer of salvation, regardless of the possible wickedness or anti-Christian religion of any of his ancestors.
At the same time, a man should realize that his decision to follow a false religion and then bring up his children in that false religion will almost certainly affect his grandchildren and great-grandchildren as well. Many of the latter will actually be children while their great-grandfather is still alive. It is a simple fact that most children (though not all) will continue in their parents' "religion." They can, if they wish, choose to leave their parents' religion and become Christians, but most will not.
What a great responsibility, therefore, each father has! He should quickly accept Christ (whose credentials as our Creator and Redeemer are impeccable!) as his Savior and Lord, and then diligently train his own children "in the nurture and admonition of the Lord" (Ephesians 6:4). HMM