Selena Gomez has obtained restraining order from the court against a man who was allegedly her stalker and wanted to kill her.

Thomas Brodnicki, the 46-year-old alleged stalker, apparently had conversations with God, following which, he planned to kill The Who Says singer.

Los Angeles County Superior Court Judge William Stewart last week gave a restraining order against the man who is listed in court documents as staying at the America Motel in Los Angeles, which is 100 yards away from Gomez house where she lives along with her parents and an assistant, LA Times reported.

Brodnicki, formerly of Des Plaines, Ill., allegedly has a long history of mental illness and a record of stalking too.

He was arrested in 2003 on charges of stalking a waitress at a Des Plaines restaurant, Des Plaines Police Chief Jim Prandini said.

Brodnicki was eventually convicted in 2008 and sentenced to three years in prison as he was found to be mentally unstable to stand the trial in 2007 and was admitted to a mental health facility, said Maria McCarthy, a Cook County assistant state's attorney, according to the report.

Again in July 2008, he was arrested in Elk Grove Village for cyber stalking. According to the police and prosecution, Brodnicki had been stalking the waitress for years together, after he first approached her at a Des Plaines convenience store. When he was arrested, he told the police that he wanted to make the woman pregnant, and that he would do that anyway, no matter what the circumstances were.

In 2010, Brodnicki was sentenced to three years in prison, but got credit for the time he spent in prison before the plea and was out of prison.

This year in September, Brodnicki traveled from Chicago to Los Angeles to meet Gomez, but police had to keep him on mental health hold for 72 hours after he told passersby that he would scratch their eyes out, according to court records.

In the court documents, the 19-year-old singer has said that she fears that Brodnicki will harm them (Selena's parents) in his attempts to see me or to harm or kill me. She also told the court that the alleged stalker visited her work place at least three times.

While Brodnicki was detained, he told a doctor that he wanted to kill the Disney star, following his conversations with God. The doctor reported Brodnicki's threats to police because he presented a serious danger of violence to Gomez, according to court records.

Los Angeles Police officials said they could not comment on threat cases or whether Brodnicki has been released.

According to court records, the LAPD's Threat Management Unit was taking Brodnicki's threat to kill Gomez extremely seriously, due to his history of stalking, criminal threats, visits to Gomez's workplace and mental illness, burbankleader.com reported.

The temporary restraining order will be heard in the court on Nov. 4 in the Burbank courthouse.