When times are tough or sad, try doing something for someone else.
Literal
Painful [when-とき], sad [when-とき][topic-は] people [for-のために] something do-[tentative-てみましょう].
つらいとき、哀しいとき — parallel temporal clauses. 人のために 'for other people' — のために marks the beneficiary. ~てみましょう 'let's try doing' is a gentle, encouraging suggestion. The sentence reads like motivational advice — outward action as a remedy for inner pain.