There's a Hindu idea of karma and a Buddhist idea of karma.

Hinduism has the whole idea that there's this universal justice system that punishes and rewards everybody.

Buddhism states that karma is influenced by the purity of ones "soul" (note, buddhism doesn't actaully believe in an eternal soul). through evil or good actions, generally how one lives their life, the essence of your consciousness is reincarnated into the a new person (and possibly animal) which most closely relates to your last state of mind. hence, an evil person is likely to return as somebody with a very negative mindset, wheras a virtuous person is more compatible with a pure and peacefull mind. however, "you" are not reincarnated, as there is no permanent "you". the essence of your conscious self becomes a part of the newly born person. also, some buddhist philosophers theorize that troubles left unresolved may influence your karma.

there are varrying views in buddhism, some believing that karma is the univers's courtroom, but I agree with the buddhist philosophy of your final consciousness influencing your next life.