An armed robber was tackled by a shopkeeper during a raid after he saw how scared the would-be thief was.
Gary Smith’s victim at first thought the masked raider might shoot him when he saw a gun in his hand after he demanded money.
But Khurram Mirza then noticed the youth's hand was shaking and he appeared to be scared and decided to confront him.
Mr Mirza pulled down the scarf Smith was wearing over his face and immediately recognised him as someone who had been in his shop "on numerous occasions", the High Court in Edinburgh heard.
Smith, who was 17 at the time, fled from the S & R Superstore, at South Street, Armadale, West Lothian, without getting any cash. Firearms officers were later called out to a house which Smith frequented but he was not there.
But Smith called police and said he had done "something bad" and wanted officers to come and get him.
On Thursday, the 18-year-old from Eastfield, Lanarkshire, admitted assaulting Mr Mirza by presenting a gun or fake firearm at him, attempting to strike him with the weapon and attempting to rob him on April 7 last year.
Advocate depute Andrew Brown QC said Mr Mirza was serving a customer when Smith walked in with a scarf covering his face.
The teenager shouted "Give me the f***ing money" as he approached the counter.
The prosecutor said: "Mr Mirza saw that the accused was holding a small black gun in his hand and initially thought that the accused might shoot him.
"However, he then saw that Smith's hand was shaking and the he appeared scared. Mr Mirza therefore decided he would take a chance and left the counter to confront him."
He grabbed Smith’s hand and realised the gun was plastic. Mr Mirza tried to make his attacker drop the gun and pulled down his scarf. The shopkeeper shouted to the woman customer to phone the police which she did. Smith tried to hit the shopkeeper on the head with the weapon but did not succeed before running away.
Later that night Smith phoned police. Officers found him at a park in Shotts, Lanarkshire where he appeared distressed and under the influence of alcohol. He said he had robbed a corner shop with a BB gun and got nothing.
The judge, Lord Burns, told the first offender that he required a background report on him before sentencing and continued the case until next month.