Instruments don't just produce one frequency at a time. When you play a single note on a melodic instruments (like piano, wind instruments, string instruments, etc.), you produce many different frequencies at a single time--a whole spectrum is produced. But this spectrum isn't random. It pretty closely follows the harmonic series, which can be thought of as the "ideal" values that most appeal to our ear. When a single note is played, the higher, often fainter frequencies that are produced are called overtones. (To read more on those, check out my answer here.) When the overtones match the harmonic series, it sounds harmonious and we get the sensation of hearing a single note/pitch. Here's an example of a waveform produced by a flute:
But when you strike a drum, the spectrum of frequencies deviates quite a bit from the harmonic series. Yes, there's often a single loudest frequency, but the overtones don't match what we expect to hear from a single-note/melodic instrument. As a result, our ears don't get the same sensation of hearing a single, defined pitch. It sounds more like a blunt collision than a defined note. For this reason, it would be much more difficult to recognize a melody on a drum than on a violin. This is called inharmonicity. A single strike on the timpani produces a spectrograph like this:
According to hyperphysics, the timpani's overtones would theoretically would be these multiples of the lowest/fundamental frequency: 1, 1.35, 1.67, 1.99, 2.30, 2.61. This deviates quite a bit from the ideal-sounding harmonic series, where the overtones are integer multiples of the lowest/fundamental frequency.
This might raise the question: why aren't the overtones of a drum harmonic? What physical quality of an instrument causes this inharmonicity? (Harmonic = integer multiple of the lowest/fundamental frequency.) It comes down to this: a vibrating circular membrane has an extra dimension within which it can vibrate compared to a 1D string or a 1D column of air. This extra dimension gives rise to both symmetric and asymmetric vibrations. For timpani, the symmetric vibrations all produce inharmonic frequencies which aren't integer multiples of the fundamental frequency. And only 5-6 of the asymmetric vibrational modes are harmonic. Those are called the "preferred modes," and they're far and few between compared to the overtones of a melodic instrument.
But beyond this, there's another logistical reason why drums aren't as well-suited for a melody as melodic instruments. Drums are tuned in advance of a performance and many can't really be re-tuned on the spot. However, there are jazz drummers who use a technique called "melodic drumming." One of the most well-known is Ari Hoeing. Here's a video from his YouTube channel of him playing You Are My Sunshine. You'll see him pushing down on the drums to increase the tension and produce a higher pitch. It's definitely recognizable, but perhaps compared to the saxophone, it's a little harder to distinguish the notes that the drums are playing.