Both. Gambling can affect your mental health, especially when you have been gambling for a long time and have lost more than your fair share. Conversely, someone who has mental health problems, especially impulse control problems, or a tendency to impulsive behaviour, can end up in a very bad way if they gamble. In extreme cases this is a fish that bites its own tail, impulsive people who lose a lot with gambling and this causes them to enter a depressive emotional state in which at times they regret it but which triggers their impulsivity even more and they return to gambling losing more and more.