Pickups were invented around 1923 to make a louder sound. They take the movements of the strings of the guitar and route them to an amplifier. A pickup is relatively simple. It consists of a magnet wrapped in fine copper wire. To focus the magnetic field across the strings, pickups are either individual magnets directly under each string or a single bar that runs under all the strings.
Metal objects in a magnetic field affect it.
A guitar string at rest has little affect on the field, so there's no sound. When a string is plucked, it's vibration creates a disturbance. The electrical disturbance is transmitted through the wire around the magnet to an amp, which changes the electric pulses into the sounds we call music. There are many elements that affect the quality or tone of the sound produced. A string with greater mass will vibrate more slowly and affect the magnetic field differently than one with less mass.