Certainly luck plays into it. There's luck in having the engine quit within gliding range of a good field, there's luck in dodging a dust devil that hits you on takeoff, there's luck in having the field stay VFR long enough for you to land.
But you do make much of your own luck.
Let's look at the odds. In 2021, about one in every 175 aircraft in the US suffered an accident. In contrast, about six of seven visitors to Las Vegas loses money. Yet there are some—using a combination of skill, knowledge, ability to assess risk, and luck—that manage to go home with more money than they came with.
The same thing works with aviation safety. With skill, knowledge, the ability to assess risk, and yes, luck, you can reduce your chances of being the one out of the 175.
One thing I'd like to emphasize is to look at EVERY accident as something that could happen to you. Don't automatically dismiss them with, "Well, I'll never be THAT stupid." LOOK at the mistakes the pilot made, imagine what you might do to salvage the same situation.
Ron Wanttaja