A rare period of downtime gives the U.S.S. Enterprise staff a chance to pursue recreational interests. Geordi conducts an experiment with Data, attaching the android to the Enterprise computer to see if he can be used as a backup. Meanwhile, Worf, Alexander and Troi transport to 19-century South Dakota, where they engage in a fantasy involving a murderous outlaw named Eli Hollander.
On the Enterprise, the crew's pursuits are interrupted by tiny malfunctions in the system. When lines from Data's poetry replace the script in a play that Beverly is rehearsing, Geordi realizes that these malfunctions could be a result of his experiment with Data. At the same time, in South Dakota, Alexander is kidnapped by two of Eli's henchmen. Frightened, he tries to stop the Holodeck program, but his command is ignored. Instead, he is taken to meet Eli's father, Frank — a man who looks exactly like Data.
Worf soon goes in search of his son, and meets Frank in the saloon. He assumes Frank is simply Data playing the game, but when his violent behavior makes him suspicious, Worf orders the computer to stop. As in Alexander's case, nothing happens, and Worf realizes that something is terribly wrong. He runs out of the saloon, sustaining a gunshot wound to the arm in the process, and explains to Troi that the computer is malfunctioning and that Alexander has been taken. Before they can make a move, they encounter Eli Hollander, who is now also a dead ringer for Data.
Troi reminds Worf that since the scenario is a holodeck program, there are built-in safeguards. While they cannot end the program on command, it will terminate on its own if they reach the end of the story. With no other choice, Worf makes a deal with Frank to trade Eli for his son, hoping that will help bring about the program's end. But while spending time with Frank and Eli, Troi makes a horrifying discovery. The two men not only look like Data, they also have Data's android abilities. Should a shoot-out occur between Worf and Frank, Worf will almost certainly lose. At the same time, the senior staff meets in the Observation Lounge and is surprised to notice that Data is speaking with a Western drawl.
Geordi realizes that parts of Data's memory have been crossed with the computer's recreational database. While Geordi tries to correct the problem, Worf prepares for his showdown with Frank. Frank arrives and releases Alexander as promised, but then he and Eli shoot Worf. But Worf foils them, activating a force field around his body that deflects the bullets. The two android outlaws are outwitted, and Worf orders them to leave town. However, the program does not end until Annie the saloon owner, who now also has Data's face, gives Worf a big, embarrassing kiss.