Entirely avoiding sweet treats is an unrealistic expectation, but there are ways you can indulge more safely.
Hard sweets and especially those that are sticky or sour can be nice to eat and last a while but will bathe your teeth in sugar and acid for longer. The longer your teeth are exposed to sugars and acids, the greater the damage to your tooth enamel as it will gradually soften and erode, increasing the risk of cavities. Instead, try to choose chocolate and preferably a brand with a high cocoa content. Chocolate is preferable because it melts easily and is more quickly washed away by saliva. Other soft treats that are safer to eat include peanut butter cups that melt in the mouth.
After eating your sweet treats, rinse your mouth with water and wait half an hour before showing your teeth a little tender loving care by brushing and flossing them. Waiting allows pH levels in your mouth to normalise more easily so your tooth enamel re-hardens. If you brush your teeth while your mouth is still very acidic, your tooth enamel is softer and more easily damaged by your toothbrush.