Flashback
Twilight Sparkle was programming the robot. "Hours of sweat and...blood...will all finally pay off in the end. I just know it.", muttered Twilight, deep into concentration. After several minutes had passed, a small bolt of lightning shot out of the robot's head and hit Twilight squarely on her left cheek. "Ow!", shouted the purple mare. She then saw a hint of red coming from the machine's eyes. Twilight ignored it and continued working on the main program.
Flashback Over
Twilight and Pinkie Pie got up after Twilight told her about the robot. "I think the robot-pony is in the back.", exclaimed Pinkie. The duo soon start walking their way to the back of the pastry shop. As they were walking, Twilight stepped into the remains of Mr. Cake's intestines. "Ew!!" shouted Twilight.
"Twilight NO! What have you done! We're all gonna die now!!" yelled Pinkie Pie. The sound of metal hoofsteps echoed from the kitchen. Twilight and Pinkie both looked at the kitchen doors with pure terror.
"Pinkie, I think I have a plan. All I have to do is open the hatch in its flank, type in the code: //shutdown.program and it will be destroyed. Got it?" Pinkie nodded blankly, unsure of what she said. When they walked in, they saw blood splattered everywhere, and in the corner, there were two tiny foals being ripped to shreds.
"NO!! Pound, Pumpkin.", yelled Pinkie Pie. The robot's head turned instantly around and faced the two mares. "Threat detected! Destroy all the living.", blared the robot. It started to walk towards Pinkie Pie, and claws started to come out of the robot's sides. It grabbed her by the neck, and squeezed as tight as possible. Twilight then pulled its claws away from her friend. "Don't you DARE hurt my friends you, you MONSTER!", shouted Twilight.
The robot took its metal arms and hit Twilight in the head. She then fell to the floor, unable to get up from the fall. She soon heard screams and loud crunching noises coming from a few feet away. "Twilight, help m-", choked Pinkie Pie, as that was the last thing she could utter out. The robot finished grinding and smashing what was left of the party pony and turned towards Twilight. She tried to get up, but felt a sharp pain coming from her chest. All she could do was scream as her body was being ripped apart by her creation. She felt her blood spewing everywhere. The last thing she said was, "I'm sorry everypony, I tried my be-"
At that moment, her heart stopped. The robot finished what he had done, and walked into Ponyville, where every single face was never forgotten.
Author's Note
And...scene! That's it, over! Thanks for enjoying my first fanfiction. 
It was the middle of the night, and Spike had been awoken by the sound of screwdrivers and hammers. He trudged down to the basement to find Twilight sitting on the floor, half awake and programming the robot.
"Come on Twilight, you've been down here all night. Don't you think you could give it a rest?" said Spike halfheartedly. At that moment, Twilight's head quickly turned towards the baby dragon.
"NO Spike! I have to do SOMETHING to prove to Princess Celestia that I can do more than smile and wave. And making a new and improved Royal Guard must be the next best thing!" Spike gulped, wishing he wasn't here. "Alright then, it seems like this is important to you..." whispered Spike, "...but I gotta go to bed. Goodnight again Twilight!" Once Spike left, Twilight turned back to the drone and continued working. After a few hours, she left the basement and slipped into bed.
When she woke up from her slumber, she smelled something, odd. 'Spike probably is making scrambled eggs again. But...this doesn't smell like burnt food. It smells...different.' She quickly trotted her way down the stairs into the kitchen, and found the dead corpse of Spike laying next to the refrigerator. "No...", spit out Twilight, as tears left her eyes as she wept next to her number one assistant.
Author's Note
Keep in mind that this story takes place before the season 4 finale. I know I made this WAY after the season 4 finale aired, but I'm lazy. 
After the loss of her number one assistant, Twilight Sparkle locked herself in her room, her hooves covered in Spike's blood. 'How could I let this happen to Spike? Who did this? What did this? Was it somepony I know?' She looked over to the other side of her room to see Spike's bed, untouched. After several minutes of sobbing, she heard a loud scraping noise coming from the library. She instantly got up from her bed and unlocked the bedroom door. As she was walking down the staircase, she was thinking up of a spell to use to blast the somewhat intruder.
"Hello?", she choked. 'What if this is the pony who killed Spike?!' She then use a teleportation spell to go to the front of the library. When she got there, she saw her front door ripped to pieces, and oddly-shaped hoofprints engraved into her floors leading to the door. "Oh no! What if the killer went to fend off with the rest of Ponyville!", screamed Twilight. She unfolded her wings and flew up to viewing distance of the town. 'I have to see if my friends are okay.'
Twilight flew over to Sugarcube Corner, and the front door was ripped and thrown off its hinges. She slowly walked into the pastry shop, only to find Mr. and Mrs. Cakes' bodies sprawled across the front counter. She then saw Pinkie Pie curled up in a ball on the floor, rocking back and forth and muttering strange noises. "Pinkie, I'm so glad you're okay!", said Twilight excitedly.
"Shhh!! Don't make another sound! 'It' is still in here!", whispered Pinkie. "It? What are you talking abo-" She then regained something, a memory of the events that took place last night.