Please tell us more details about your setup: OS version, exact G5 model, Energy Saver settings and anything else you think may help us diagnose your problem. "My computer won't stay asleep," isn't enough information to even begin troubleshooting.
My only guess would be that you have some USB devices other than your keyboard and mouse connected (a printer, a hub, etc.) that are causing the computer to immediately wake. If so, try connecting only your Apple-supplied keyboard and mouse to the computer and see if that helps -- if so, you can, by testing and process of elimination, narrow down the culprit device.