As the debate rages over how to prevent future school shootings, it's emerged there may have been dozens of opportunities to stop Florida gunman Nikolas Cruz before he killed 17 people last week.

Local law enforcement declined to arrest Cruz on numerous occasions, including two incidents in which he allegedly involving a gun. The FBI failed to follow through on two reports pegging Cruz as a possible school shooter. And Thursday it was revealed a cop on the school campus Cruz targeted chose to hide rather than fight.

Palm Beach County police officers were posted outside the home of disgraced former deputy Scot Peterson on Friday following his resignation a day earlier, after officials – citing surveillance video – said he “never went in” Marjory Stoneman Douglas High School while the attack was unfolding.

“He should have went in, addressed the killer, killed the killer,” his ex-boss, Broward County Sheriff Scott Israel, said after reports emerged Thursday of Peterson’s inaction, prompting widespread outrage.

But rewinding the timeline from the moment Cruz burst through the door of the Parkland school on Valentine’s Day, there now appears to be countless instances where law enforcement, academic and medical officials could have stopped the 19-year-old Cruz and spared the lives of the young students and staff killed in one of the country’s deadliest school attacks.

FBI gets two warnings about Cruz, specifically involving the possibility of a school shooting

In a scandal prompting Attorney General Jeff Sessions to order an “immediate review," the Federal Bureau of Investigation said it received a tip about Cruz the month before the attack, but mishandled the information after receiving the call.

“The caller provided information about Cruz’s gun ownership, desire to kill people, erratic behavior, and disturbing social media posts, as well as the potential of him conducting a school shooting,” the FBI said in a statement.

However, the information that agents were told Jan. 5 by the caller, identified by the bureau as someone close to the shooter, never made it to the FBI’s Miami Field Office, “where appropriate investigative steps would have been taken.”

The information the caller presented also “should have been assessed as a potential threat to life," the bureau admitted.

Months earlier, in September, the FBI also received a tip about a troubling YouTube comment made by a user named “Nikolas Cruz” that said “I’m going to be a professional school shooter.” A special agent in charge of the bureau’s Miami division said the comment was investigated but authorities could not determine its origin or find any connection to South Florida, where the shooting took place.

"It is now clear that the warning signs were there and tips to the FBI were missed," Sessions said after reports of the blunders emerged. "We see the tragic consequences of those failures."

Local police pay visit after visit to shooter’s home, but Cruz manages to stay out of jail -- or a hospital

Frequent fights with their mother and each other. Items being thrown about. One “out of control” escapade after another allegedly involving Cruz and his brother Zachary unfolded at the home of their adoptive mother in Parkland, according to police records.

Despite local law enforcement reportedly receiving dozens of callsbetween 2011 and 2016, with issues ranging from “domestic disturbance to child/elder abuse," state investigators deemed the shooter low risk and felt he was unlikely to hurt anyone other than himself.

Israel admitted in the wake of the shooting authorities received "20 calls for services in the last few years,” with local media putting the number as high as 39. Israel says every one of those calls will now be “looked at and scrutinized.”

Social services and mental health professionals also investigated Cruz in 2016 after Snapchat videos were uncovered showing him cutting both of his arms.

But a visit by a mental health clinician at Henderson Behavioral Health ended with a determination Cruz “was not at risk to harm himself or others,” and the teen was instructed to sign a safety contract.

A Florida Department of Children and Families report obtained by Fox News also showed that it closed its investigation into Cruz in November, “based on his caregiver’s protective capacity, in-home services through Henderson, and engagement in school."

Months later, after Cruz's massacre, he told police that voices in his head -- called “demons” by law enforcement sources -- told him to carry out the attack, according to reports.

School ‘disciplinary problems’ start piling up

Cruz was frequently in trouble at school in the years leading up to the shooting.

He was suspended for a day in January 2017 for assaulting someone and got into a fight months earlier, according to disciplinary records obtained by the Sun-Sentinel. The records also said Cruz’s adoptive mother was called in more than a dozen times for discussions and Cruz was often sent to counseling.

One report mentioned bullets were found in his backpack. A former classmate said Cruz followed her around, would abuse his girlfriend and even talked about killing his friends' parents. The former classmate and another student also claimed the shooter used to sell knives out of his lunch box.

Cruz ended up getting expelled from Marjory Stoneman last year for “disciplinary problems” and bounced around a few alternative schools before reappearing there, rifle in hand, on Valentine’s Day.

Reports also linked Cruz to frequent trouble during his time at Westglades Middle School, where he apparently was disciplined for insulting teachers and staff, using profanity and racking up unexcused absences and at least one fight.

An officer was on scene during the shooting, and did nothing

Peterson was near the shooting site for four minutes of Cruz's six minute rampage. But instead of the armed, trained officer engaging Cruz -- something that could have saved several lives -- Peterson remained outside, taking shelter behind a concrete barrier, according to authorities who viewed surveillance film.

President Trump lambasted Peterson on Friday after being asked about the former deputy.

"When it came time to get in there and do something, he didn't have the courage, or something happened," Trump said. "He certainly did a poor job. That's the case where somebody was outside, they are trained, they didn't react properly under pressure or they were a coward."