I have sometimes found trash or lint, etc, underneath a key or spacebar which might be the problem. You can gently look around underneath the space bar for something that you might be 'clogging up the works'.
Sometimes a space bar will work OK on one edge, but not the other edge. That might be more annoying than not working at all. If you can't get the spacebar to work - it's pretty simple: Replace the keyboard.
You could just plug in any USB keyboard (doesn't need to be anything Apple, just a generic USB keyboard), and make sure the space bar is working on a different keyboard.
What kind of Mac do you have? MacBook? iMac? MacPro? something else? Separate keyboard is simple. A laptop, you can decide if you want to spend the money on a 5 or 6 year old Mac, or just use an external keyboard. It's a little less portable, but still should work!