Okay, let's start with the basics. Two guys. William Afton and Henry. Both characters are the co-owners and creators of the Freddy Fazbear Pizarria franchise and their animatronics. William has three kids, two sons and a daughter. William also has a dark secret, that he's really into murdering kids. Like really into it. So much so that he started murdering kids at his restaurants.
Back then, kids were monitored by a Puppet robot who tracked kids by colored wristbands. When one kid, who turns out to be Henry's daughter, goes missing, the specific Puppet animatronic ventured outside the restaurant and into the rain where its robotic body began to deteriorate. Not before finding the girl, having been fatally wounded by William, in a ditch. The puppet in its final moment fell beside the dying child's body. As the girl passed her soul inhabited the Puppet, and thus the first animatronic was possessed.
William Afton continued his spree of kid killing, specifically by dressing up in a Freddy Fazbear animatronic (btw, the animatronics were designed in such a manner that a person could safely wear them, so long as proper maintenance was made) and luring kids to their demise. During one of these killings, Afton's younger son witnessed thie gruesome murder by the hands of an animatronic and become incredibly fearful of them. This made him the easy subject of taunting by his older brother, Michael Afton, until it culminated in the Michael hoisting the younger into the open maw of a Freddy animatronic as a prank. Unfortunately, the animatronic snapped its jaws down on the younger son and put him into a deep coma (his nightmares in this coma are FNAF 4). Michael Afton grows incredibly distraught. The Puppet finds the four souls of the victims killed by William Afton and grants them "life" by allowing their souls to possess the animatronics (Freddy, Bonnie, Chica, and Foxy) with the ultimate desire of getting revenge on William Afton.
William Afton continues his rampage, now getting the idea to design the animatronics themselves do the murdering. He creates Circus Baby (The main Sister Location animatronic) and begins making the animatronics with AI. He also instructs his young daughter, Elizabeth, to not go anywhere near them. She disobeys, and becomes lured in by Circus Baby before being killed by via a claw hidden within the animatronic's torso pulling her inside.
Michael Afton, now having lost both of his siblings to animatronics, becomes incredibly suspicious of his father and goes undercover to work at the Circus Baby Entertainment and Rental location (this is the plot of Sister Location). Here he encounters the animatronics with advanced AI and over the course of the week he is tricked, or otherwise coerced, into helping them out. The animatronics want nothing more than to leave the place, but know they cannot exist in society looking the way they do. So, they scoop out all their robotic parts, combine them into one being known as Ennard, and trick Michael Afton into getting himself in the scoop machine. Michael's insides are scooped out from him allowing ample room in his body for the animatronic skeleton to wear him like a suit.
Okay, so here's where it gets weird.
Somehow, the scoop also has this weird soul retaining ability that allowed Michael Afton's soul to remain with his hollowed out body. This didn't mean the body itself survived, however. As Ennard continued to wear his body, it began to rot, y'know because it was kinda dead. Because this meant that it could no longer wander in public freely, Ennard eventually had to flee the body, leaving Michael's soul to regain control of his semi-corpse body. Sometime after this, the animatronics of Ennard and Baby separated.
Michael, still focused on getting to the bottom of his father's crimes, began working at various Freddy Fazbear locations under aliases (FNAF 1 and 2) before ultimately getting fired for messing with the now hostile possessed animatronics and "bad odor" (y'know 'cause of the decaying body).
However, the four animatronics violent actions do catch the attention of William Afton. Hoping to get them before they can get him, Michael lures them one by one and dismantles the animatronics. However, their spirits pursued him regardless and cornered him in an room within an abandoned Fazbear location. Needing to hide, William darts into an old animatronic costume and wears it like a suit. However, the decayed and withered mechanics of it cause the springlocks to close in on him and William dies a horrific and slow death inside the suit.
This isn't where William's story ends, however. Much like the others, William's soul possessed the animatronic becoming Springtrap. Years later, the horror stories of the Fazbear restaurants become public knowledge and a haunted house around the events were made called Fazbear's Fright. The Springtrap animatronic was found and put into Fazbear's Fright as an attraction, but begins to hunt the night guard before the faulty wiring burins the whole place down (FNAF 3). Springtrap survives the fire, however.
Now we arrive at FNAF 6. Michael Afton is contacted by Henry, via audio messages, to start his own Pizarria franchise. Over time, Michael finds various animatronics and refurbishes them into the restaurant. These are Molten Freddy (The surviving Ennard), Scrap Baby (the remains of Circus Baby), Springtrap, and Lefty, an animatronic created to entrap the puppet within its suit. On the final day, it's revealed that Henry instructed Michael to gather all the animatronics together in one location and be their target as a trap. The exits are locked and the pizarria is set ablaze, taking out the animatronics and any souls still attached to them with them. Michael decides to perish within the fire, his mission now having been accomplished. All the restless souls are set free.