That is great information, thank you. When I hear music I love, my first intuition is "yes, more of this!". So my riffs are definitely not the same riff or melody as anyone else's, but some of them have a strikingly similar vibe/groove. Can you get in trouble even for that?
Most of the replies here are more or less correct but:
You are only ever going to get into 'trouble' if someone takes you to court, and that will only happen if you make a shedload of money from your recording. Even then, you don't have to go to court, you can add the person's name as a songwriter and split the proceeds - after all, that is the outcome they are looking for should it get as far as the court.
Second, you can spend ten years researching other tracks to see if yours is original, and only just scratch the surface. The fact is, it's all been done before. That chord sequence you wrote? It's been done thousands of times already. That vocal melody? You may well have genuinely thought it up yourself, but somebody somewhere will already have done it. Lyrics are a bit easier to be original with, there are far more word permutations than there are musical ones.
That riff? Well again, someone, somewhere will already have done it, that's pretty much guaranteed.
So I wouldn't worry too much. If the song you wrote sounds
exactly like a song that you know, then of course, you may want to rethink it. But I wouldn't worry too much about the opinions of others, it's all subjective. Just go ahead and record. If you get sued because you made millions, it's a nice problem to have.