One day, SpongeBob wakes up and begins playing fetch with Gary, leading the snail to dig up a treasure chest. SpongeBob opens the chest and finds a magic bottle, which, upon rubbing it, releases doubloons all over Bikini Bottom and releases The Flying Dutchman. The Flying Dutchman tells SpongeBob that he will take Gary to work on his ship for all eternity; after briefly leaving to check on his ship, he makes good on this promise.
SpongeBob proceeds to travel across seven different worlds to recover letter tiles; there are nine in each world, which spell out his name, and each set leads to a treasure. These treasures, as explained by one of Squidward's books on "How to Defeat Evil Spirits", are personal possessions from when the Dutchman was alive, which can apparently weaken him; according to the book, collecting all seven will make SpongeBob immune to the Dutchman's hypnotizing spell, allowing him to put up a fight to save Bikini Bottom.