Luffy's goofy personality is the perfect offset to One Piece's dark setting.
Luffy's Godly Secret Oda doesn't want you to know
Eiichiro Oda is a master craftsman who knows how to balance an extremely dark plot in a way that is palatable to fans of all genres. One Piece is the perfect example of a series that tackles serious issues, but the main character takes the stress burden off the fans.
If not for Luffy, One Piece would have been another psychological thriller or dark adventure series. However, due to the author's well-planned characters and their chemistry together, the franchise is currently among the reigning kings of the anime/manga world.
Right from the beginning of One Piece, fans have been exposed to some extremely dark plot lines. In fact, every Straw Hat has a dark past that's enough to make you cry. Whether it's Brooke whose crewmates died before his very eyes, Nami who was enslaved by the Arlong Pirates, or Robin, who spent her entire life running away from death.