The Lord passed before him and proclaimed, “The Lord, the Lord, a God merciful and gracious, slow to anger, and abounding in steadfast love and faithfulness, keeping steadfast love for thousands, forgiving iniquity and transgression and sin, but who will by no means clear the guilty, visiting the iniquity of the fathers on the children and the children’s children, to the third and the fourth generation.” (Exod 34:6-7)
Here is what one commentator writes about 'generational sins:'
God then issued a corrective against the natural human tendency to accept grace on the assumption that because an infinite God can produce an infinite amount of grace, sin has no significant consequence. This corrective is introduced simply by the normal Hebrew word for “and,” which the NIV justifiably translates “yet” but which is not a strong adversative word. Perhaps an even more revealing, even if tendentious, translation would be something like: “[Forgiving wickedness, rebellion and sin] and at the same time not letting anybody off [i.e., making sure that the guilty get what they deserve].”
In connection with the wording “he punishes the children and their children for the sin of the fathers to the third and fourth generation,” see comments on 20:5–6. As already suggested there, this wording means something quite different from what it might seem to mean to the casual reader. It does not mean that God would punish children and grandchildren for something their ancestors did but that they themselves did not do. Rather, it describes God’s just punishment of a given type of sin in each new generation as that sin continues to be repeated down through the generations. In other words, God here reminded his people that they could not rightly think something like “we can probably get away with doing this in our generation because God punished an earlier generation for doing it, so the punishment for it has already been given, and we don’t have to worry about it.” Douglas K. Stuart, Exodus, vol. 2, The New American Commentary, 717.