Generally speaking, I think that it would be best to copy-paste the whole program here, unless it is very long, because it can be that you are introducing or fixing bugs when partially copying and pasting from your code. Also, the best way for us to inspect the code would be to try to run it - but that is not possible without us reconstucting a whole program around the fragment. The reconstruction will not be the same as your original code and might not be encompassing the same bugs.
The indentation seems fine now. Do you still get the error message? The error "name 'event' is not defined" must mean that the statement "if event.type == pygame.KEYDOWN:" had gone out of the scope from where the name event was defined (" for event in pygame.event.get():") and because that the interpreter did not understand what you meant with 'event'. The only explanation I can guess is some formatting/intendation error.