Daniel Grizzle, aged 42, was found in possession of the class A drugs on September 8, 2021, after being stopped by police in Wolverhampton.
Grizzle had been seen approaching a vehicle which police believed had some involvement in drug dealing on the day he was arrested.
When he noticed the officers, he began to turn back, but was found with "a substantial amount of drugs", totalling 53 wraps of heroin and crack cocaine.
Grizzle, from Jonesfield Crescent in East Park, Wolverhampton, pleaded guilty to possession of both drugs at a previous hearing.
District Judge Adrian Lower, sitting as a recorder at Wolverhampton Crown Court on Friday, told Mr Grizzle: "If you really want to take those drugs, it's up to you, but I must say that possession of them is illegal and taking them won't do any good for your health."
He also stressed to Grizzle that "the courts take drug using seriously".
Judge Lower added: "We've been extremely patient in giving Mr Grizzle time to see the probation service, I'm not sure why the court even needed to be so patient.
"The probation service is not willing to see him again and I'm not giving him another opportunity."
The court heard that Grizzle had previous convictions including for possession of cannabis in 2003, for which he received a community order.
For possession of drugs, Judge Lower sentenced Grizzle to a 12-month community order on Friday, with a requirement that he must complete 200 hours of unpaid work and pay costs of £85.
The judge also ordered the forfeiture and destruction of the drugs and paraphernalia.
Miss Amanda O'Mara, prosecuting barrister, offered no evidence relating to two counts of supplying drugs.