It was the truth, but Jesus could see into the young rich man's heart and knew he loved his money and was not without sin. Like many men, the young man was self-righteous (as are all those who claim they keep the law).
Philippians 2:13 For it is God which worketh in you both to will and to do of his good pleasure.
2 Corinthians 12:9 And he said unto me, My grace is sufficient for thee: for my strength is made perfect in weakness. Most gladly therefore will I rather glory in my infirmities, that the power of Christ may rest upon me.
Those who are really saved have the love of God shed abroad on their hearts. It's not necessary to lecture them about those things you might imagine. The fact is that we are not in the flesh if the Spirit of God lives in us. Romans 8:9