I can hear my guitar through the computers speaker but I cannot record it on audacity. I can record on my computers sound recorder but audacity is giving me an error message.

Microphone + speakers is a recipe for disaster.
If you are recording with a mic and the sound comes through speakers, the mic will pick up the sound from the speakers and at best will create a hollow echoey sound. At worst it will scream with feedback.

Please state which version of Windows you are using, the exact three-section version of Audacity from Help > About Audacity and whether you obtained the .exe installer or the zip.

What exactly are you trying to record, and what equipment are you using?