Children do not always follow their parents' example. If a father shows that gambling is bad, that he has lost more than he has won, he can influence his son positively, perhaps. But that is not necessarily true.
Friends can have a big impact: if they play, you feel pressure to follow them. But even here, that's not a given.
I think it's a personal thing that matures with many psychological factors, not just one
It's indeed a personal thing; even if the parent gambles all day in front of a child, they can still decide not to gamble and not gamble at all, or even if the parent doesn't gamble at all, the child can turn out to be a gambler in the future. It all boils down to what the person wants; like the saying goes, it's only those who want to be influenced by others that will get influenced. It's a personal something.