When you pluck a guitar string it vibrates and causes compressions/decompressions in the air which travel to your ear.
Same thing happens when you slam a door etc. The impact of the two objects causes them to distort slightly and then they vibrate back and to for a short time and compress and decompress the air which again travel to your ear.
Because these objects (like doors and door frames) are very rigid compared to a guitar string, they soon stop vibrating and so the sound only lasts for a short time.
Think also of a ball hitting a tennis racquet: the ball is compressed slightly and the racquet strings are stretched slightly. When the ball springs back and the strings tighten up again they create sound waves. Again the ball is difficult to compress and the strings are hard to stretch and so they soon return to where they were and so the sound doesn't last for long.