Cats wave their tails for many reasons. Other aspects of what it does with its tail and its general body posture can help inform what is the exact reason it's waving it.
How intensely is it waving its tail? Is it rather slow and gentle? Or is it waving it hard enough to thump against things, and rather quickly? Is it mostly the tip of the tail that's twitching, or is it the entire tail?
Generally the more intensely the tail is being waved, the more alert or agitated the cat is. A rather violently lashing tail usually indicates the cat is very tense, and either that it's mad or afraid or maybe that it's very stressed out. A more medium level generally indicates the cat is riled up over something, but it's not necessarily a negative thing. For example, a cat might lash its tail some while playing or watching prey. A little bit of twitching may indicate the cat is on the alert, even if it otherwise seems sleepy, or it might twitch its tail a bit while being friendly.
The tail's position, if the cat is standing, might also indicate something about the cat's mood as well.
Held straight up indicates confidence. Generally when the tail is straight up, cats only might wave it a bit as a friendly sort of greeting. They also might keep it steady with a hook at the end. This is a very friendly and inquisitive posture, which people often call "question mark tail."
A tail held low indicates the opposite. The cat is not confident at all, and a waving tail is generally more of an indication of stress.
If the tail is more in a neutral position, the cat might be unsure, or if the tail is waving, it might indicate things like stalking prey or playing.
Lastly, if the cat's tail is arched, and may or may not be fluffed, that's usually a sign it's very afraid or aggressive. However, this also can be a play behavior which is more common in kittens, but some adult cats may also do it. You can try to tell the difference by how generally intense the cat is being, (a cat that is serious is much more intense than one that's just playing), but it also helps to know the animal. If the cat does this same behavior while attacking toys, then you know this is one of those cats that likes to make that posture during play.