The hit is scored the moment the batter reaches first base safely; if he is put out while attempting to stretch his hit to a double or triple or home run on the same play, he still gets credit for a hit (according to the last base he reached safely on the play).
A hit is awarded when the batter successfully reaches first base. If the batter attempts to advance further and gets out while attempting to reach a double, triple, or home run, they are still credited with a hit based on their final safe base.