Sustain effect in electric guitar is similar with compressor effect. The purpose of this effect is to make the note last longer when the string is plucked. The mechanism is actually work by controlling an amplifier gain, where the gain is automatically increased when the note fade out, therefore the note will be sustained to be heard until the actual sound almost completely gone.
You need a red LED and a small LDR (light dependent resistor) to be assembled and protected in a lightproof case. Select a small LDR and Red LED, set their layout that the LED ray directly expose the sensitive surface of the LDR, protect the LDR and the LED with lightproof glue, case, or anything can be used to avoid the LDR receiving any light other than from the LED. The LDR will be about 100-200 K ohm in dark condition and about 1-5K? in day light exposure. You can use BC549 transistor type if you can’t find BC209 type in your local store.