In 1977, Eddie Adams is a high-school dropout living with his stepfather and emotionally abusive, alcoholic mother in Torrance, California. He works at the Reseda nightclub owned by Maurice Rodriguez, where he meets porn filmmaker Jack Horner, who auditions him by watching him have sex with Rollergirl, a porn starlet who always wears skates. After having an argument with his mother about his girlfriend and sex life, Adams moves in with Horner at his San Fernando Valley home. Adams gives himself the screen name "Dirk Diggler", and becomes a star because of his good looks, youthful charisma, and unusually large penis. His success allows him to buy a new house, an extensive wardrobe, and a "competition orange" 1977 Chevrolet Corvette Stingray. His friend, porn star Reed Rothchild, and he pitch and star in a series of successful action-themed porn films. Dirk works and socializes with others from the porn industry, and they live carefree lifestyles in the late 1970s disco era. That changes at a New Year's Eve party at Horner's house marking the year 1980, when assistant director Little Bill Thompson discovers his porn-star wife having sex with another man, shoots them with a gun, and kills himself.
Dirk and Reed begin using cocaine. Due to Dirk's drug use, he finds it increasingly difficult to achieve an erection, falls into violent mood swings and becomes upset with Johnny Doe, a new leading man Jack recruited. In 1983, after having an argument with Jack, Dirk is fired, and he and Reed leave to start a rock and roll career along with Scotty, a boom operator who loves Dirk. Jack previously rejected business overtures from Floyd Gondolli, a "theater" magnate in San Diego and San Francisco, who insists on cutting costs by shooting on videotape, because Jack believes that the tapes will diminish the quality of his films. After his friend and financier Colonel James is imprisoned for creating films depicting child pornography, Jack works with Floyd, becoming disillusioned with the lack of scripts and character development in the projects Gondolli expects him to churn out. One of these projects involves Jack and Rollergirl riding in a limousine, searching for random men for her to have sex with while a crew tapes it. When one man recognizes Rollergirl as a former high-school student, he insults her and Jack, who both attack and leave the injured man on the sidewalk as the crew drives away.
Leading lady Amber Waves, who took Dirk under her wing when he joined Jack's stable of actors, finds herself in a custody battle with her ex-husband. The court determines she is an unfit mother, due to her involvement in the porn industry, prior criminal record and cocaine addiction. Buck Swope marries fellow porn star Jessie St. Vincent, who becomes pregnant. Because of his past, Buck is disqualified from a bank loan and cannot open his own stereo-equipment store. That night, he finds himself in the middle of a holdup in which the clerk, the robber and an armed customer are killed. Buck escapes with the money that the robber demanded. Having squandered their money on drugs, Dirk and Reed cannot pay a recording studio for demonstration tapes they believe will enable them to become music stars. Desperate for money, Dirk resorts to prostitution, but is assaulted and robbed by three men. Dirk, Reed and their friend Todd attempt to scam drug dealer Rahad Jackson, by selling him a half-kilo of baking soda as cocaine. Dirk and Reed decide to leave before Rahad's bodyguard inspects it, but Todd fails to steal money from Rahad, who kills him in the ensuing gunfight. Dirk reconciles with Jack.
In 1984, Buck and Jessie gives birth to their son, Amber shoots the television commercial for Buck's store opening, Reed practices a successful magic act at the strip club, Colonel James remains in prison, and Rollergirl returns to high school. Dirk and Amber prepare to start filming again.

Question: Why does Dirk have a problem maintaining an erection?
Answer: He began using drugs.
Alternative answer: Beause of his cocaine use.