Masturbation, in Buddhist precepts, belongs to lewdness. According to Buddhist scriptures, lewdness not only leads to bad luck in this life, but also leads to serious karma in later generations.
The ancients said "the head of all evils", a bad habit, must be completely quit, and there will be a happy life.
The specific precepts can draw lessons from the impure view and the view of bones in Buddhism.