The gunman who went on a rampage inside a Louisville bank sent a text message to his family just minutes before the massacre, saying “I love you” — as his roommate said he had no idea about his close friend’s deadly plan.

A lawyer for Connor Sturgeon’s family revealed the 25-year-old man’s final message of affection before he stormed into the Old National Bank with an assault rifle and opened fire on his colleagues on Monday.

Meanwhile, Sturgeon’s roommate has revealed that he had no idea that his close friend was planning the massacre, which left five people dead and eight others injured, including a cop who remains in critical condition.

The roommate, 24-year-old Dallas Whelan, has been cooperating with the investigation into the mass shooting, his lawyer told the Daily Mail.

“It was as unknown and surprising to Dallas as everybody,” said the lawyer, who also is representing Sturgeon’s family, adding that Whelan didn’t know Sturgeon had legally bought the assault rifle six days earlier.

“The (Sturgeon) family is still working with law enforcement. They don’t know much,” the lawyer said.

“We were told by police that there are letters and things. We do not have them. We have not seen them, so we’re still trying to put that together too.”

Follow The Post’s latest coverage of the shooting in Louisville

Sturgeon’s neighbor Michael McCoy, 45, has told The Post that Whelan called the police and reported finding a letter from his roommate.

“[The roommate] seemed like he was tripping, like he couldn’t believe any of this,” McCoy said. “They found a letter and a note he wrote and reported it to the police.”

On Tuesday, Sturgeon’s parents said in a statement that their son had been struggling with mental health issues, but that they never imagined he could unleash such an atrocity.

“While Connor, like many of his contemporaries, had mental health challenges which we, as a family, were actively addressing, there were never any warning signs or indications he was capable of this shocking act,” they said.

“While we have many unanswered questions, we will continue to cooperate fully with law enforcement officials and do all we can to aid everyone in understanding why and how this happened,” the family added.

The family did not specify Sturgeon’s mental health issues, but a former classmate said he had suffered countless concussions from playing football in high school.

It was previously reported that Sturgeon had left a voicemail to a friend saying he felt “suicidal” and planned to “kill everyone at the bank,” where he was about to be fired.

The dead victims have been identified as Tommy Elliott, 63, a senior vice president; Jim Tutt, 64, a market executive; Joshua Barrick, 40, another senior vice president; Juliana Farmer, 45, a commercial loan specialist; and Deana Eckert, 57, an executive administrative officer.

Rookie officer Nickolas Wilt, 26, who was shot in the head, has undergone brain surgery and remains in critical but stable condition.  

Another cop, Cory Galloway, was grazed in the shoulder in the shootout in which Sturgeon was killed.