I'm a total beginner with my Nikon D5100 and i'm trying to shoot in auto mode. When I attach the AF-S Nikkor 18-55 mm lens, the camera says "lens not attached" unless I have it in M (manual) mode. I have checked and the lens is switched to A. Any help would be appreciated!
The most likely reason is a dirty contact on the camera or lens. Try cleaning these in accordance with the instructions with the lens/camera. You can clean them with a dry swab designed for this, or better, use a cleaning solution sold for this. Here is a video on the process: https://www.youtube.com/watch?v=wUt-K6w7lc0
Sometimes a lens needs a little "bit more" of the turn to engage the autofocus contact points. That could be why it's ok in manual mode. Please do not force this by any means, but just back it off a bit and close it a little bit more strongly...(like closing a door, some times it needs that extra bit more ). It's worth trying, I used to have a lens that I used to have to do it to . Be pleased to know how youy get on !