Toby’s main function was to tend to three children aboard the ship, and the robot had been programmed appropriately.
Toby was modified by the commander of the ship, Stuart Hickson, fitted with an emotional response gadget that allowed it to feel emotions. Hickson thought this would help the robot maintain the ship’s systems after the entire crew went down to the surface of Artemys 314. But three days later, Hickson called for help and the robot panicked. It was able to send an SOS, to which the USS Enterprise responded. But it was afraid when a landing party boarded the ship, and fired a phaser to scare off the team. Montgomery Scott was able to reduce the intensity setting of its emotional circuits and learn what happened to the crew. (TOS comic: "All the Ages Frozen")