A branch of Hot Flame restaurant. Picture: google maps

Scott Beattie, 31, targeted the schoolgirl after her parents – who were regulars at the family restaurant in Livingston, West Lothian – let her go to the loo on her own because she knew the place so well, Livingston Sheriff Court heard.

As the youngster was washing her hands in the ladies’ toilet, Beattie entered, told her: “Come here” and pushed her into a cubicle before locking the door.

He then dropped his trousers, exposing his genitals to her, sat down on the toilet and tried to pull her trousers down.

Sign up to our daily newsletter The i newsletter cut through the noise Sign up Thanks for signing up! Sorry, there seem to be some issues. Please try again later. Submitting...

The terrified schoolgirl resisted him by holding on to the top of her trousers and he gave up trying to force them down. He released the girl who went back to her parents and told them what had happened.

Jim Robertson prosecuting, said the primary school pupil’s parents described her as being “upset” with a “shocked look” on her face.

When they asked her what had happened, Mr Robertson said, she told them the man had tried to pull down her trousers and she’d held them up.

Asked if she had tried to scream she said she hadn’t because she was “too scared”.

He added: “She said the man let her out by unlocking the door and told her to wash her hands.”

He said the girl was able to give police a description of Beattie and the distinctive yellow bag he was carrying.

Officers viewed CCTV footage from the restaurant and subsequently identified and traced him. They searched his bag at Livingston Police Station and found a multi-tool lock-knife with a 44mm serrated blade, a pair of latex gloves, and a bottle of lubricant.

Beattie pled guilty to placing the girl in a state of fear and alarm by pushing her into the cubicle, locking the door, exposing himself to her and trying to lower her trousers on 15 February 2019.

He also pled guilty to following a woman into the female toilets at the Hot Flame restaurant in Livingston Centre on 13 January, entering the middle cubicle next to hers and watching her as she used the toilet.

Mr Robertson said the woman heard a noise from the neighbouring cubicle and looked up to see Beattie peering over the top of the partition.

He said: “She was furious. She was upset. She began to shout and swear at the accused.

“She ran out of the cubicle and saw him run into the first cubicle and lock himself in. She began to bang on the door continuing to shout and swear at him.”

He said Beattie eventually opened the door and the woman asked him what he was doing. He replied: “I’m sorry, I’m sorry. I just got confused.”

She followed Beattie out into the restaurant and told staff what had happened. Security staff were called.

Beattie told them he’d gone into the wrong toilets by mistake because he was in urgent need, repeatedly saying he was sorry. Police were contacted and he was arrested and charged.

Kevin Dugan defending said he had commissioned a psychiatric report for the court because he had concerns about Beattie’s mental health. He told the court: “He is suffering from a borderline personality disorder. I’ll provide a copy of the report to the criminal justice social work team.”Sheriff Martin Edington added Beattie’s name to the sex offenders’ register with immediate effect because the case had a “significant sexual element” and deferred sentence until 4 July for background reports.