As Selena Gomez made her last appearance on Wizards of Waverly Place Friday, a Judge granted her a restraining order against an obsessive fan that had allegedly threatened to kill her.

Thomas Brodnicki will have to keep his distance from the singer/actress and will not be allowed to contact her, following a ruling from Superior Court Judge, William D. Stewart, the Huffington Post reported.

The judge had previously refused to apply the restraining order after Brodnicki failed to turn up in court and testify. Brodnicki had allegedly professed that he had over 50 conversations with God about killing the actress, according to TMZ.

The restraining order was only granted after an unusual turn of events, when Brodnicki sent a written declaration to the court saying Gomez needed protection from him.

Brodnicki, 46, who has a history of mental illness, was accused of sending death threats to the 19-year-old celebrity while he was on psychiatric hold. He was later accused of stalking gomez between the months of July and October of 2011, the Huffington Post reported.

The restraining order granted by the Los Angeles Superior Court is valid for three years and also involves Gomez's family, according to TMZ. Gomez was not present at court when the decision was made.

Meanwhile, Gomez announced that she would be taking a break from her music career. She told E! News that her band was going to chill out for a second after wrapping up the final leg of their tour in Uruguay on Feb.11.

In the next couple of months, Gomez is expected to begin work on a new movie, Spring Breakers, according to MTV. The film is apparently about a group of college girls who commit a crime during spring break and end up in jail. Rumors have also been hinting that the actress is attached to a second movie this year called Hot Mess.