Today we have the perfect example of a passage that must be read in the context of the whole bible.
"punishing children and grandchildren to the third and fourth generation for their fathers’ wickedness!”
What right thinking person would even suggest that this passage should be taken literally?
It is the product of its culture. But is there still truth in it? Yes.
It falls in the realm of psychology, a category ancient people did not have. We now understand better how the sins of parents get passed on, those who are abused, often become themselves abusers. What we now call family dysfunctional behavior will continue into the next generation until someone make a conscious break with the past. There are genetic predispositions toward certain things.
In biblical times they did not understand medicine, or genetics, or psychology so it all got laid on God.
So is there truth in this verse? Yes. Bad choices can ripple though generations. Children inherit and learn from their parents, both good and bad. But there is in every generation free will. The ability to say no further.