AFAIK on_space is called each frame while space is pressed, not only once.

I'd do something like this:
while(!key_space) wait(1);
turn_the_light_on();
while(key_space) wait(1);
turn_the_light_off();