There could be a few solutions depending on what is causing the melody to play for too long.
If you've entered notation for the melody, and the notation is longer than the space you want it to fit in, you could delete notes from just the end of the melody.
You could also just mute the melody track at the point that it is supposed to end. You can do this in the Bar Settings, by right clicking the first bar after the melody should end, selecting Bar Settings, then muting the melody track.
There might be something else causing this that I'm not aware of, and some other users might have suggestions too.
Here are some videos that could be helpful in the meantime:
https://www.youtube.com/watch?v=1EoF1BFZSzY&feature=emb_logohttps://www.youtube.com/watch?v=TF3V7LFF5do&feature=emb_logo