Two issues are discussed in Matt 19:21-24.
First, salvation is not based upon works or morality. If the young scribe had exercised simple faith in Christ, then regardless the cost in a worldly fashion, there would be treasures awaiting him in heaven. That faith was tested when Christ Himself told him to give up some wealth to the poor and there would be treasure for him in heaven. This didn’t preclude any heaven for the man, but emphasized the issue of faith.
Secondly, Christ tells the disciples that there is tremendous difficult for a rich man to enter the kingdom of God. This emphasizes how we tend to scar our own thinking by placing other things before God in our living. When we focus continually upon worldly advancement, our gains and losses directly observable in the world easily influence our thinking and distract us from exercising faith through Him.
Nevertheless, through God, all things are possible, even for a rich man to enter heaven, but again, it must be through faith in Christ.