Displaying stimulus for a limited amount of time before disappearing

I think is not changing back because the code checks the timer well before 0.5 seconds has elapsed. Try this way:

#in the begin routine tab

opacClock = core.Clock()

# in the each frame tab
if key_resp.keys:
    opacClock.reset() #resets the clock back to 0
    if key_resp.keys == 'a':
        opacleft =1
        opacright=0
    elif key_resp.keys == 'p':
        opacright = 1
        opacleft=0

if opacClock.getTime() >= 0.5: #after 0.5 seconds
   opacleft =0
   opacright =0 #both opacity are set to 0

For the JS conversion look at this: PsychoPy Python to Javascript crib sheet

Also, changing the opacity online seems to cause a lot of problem, so if you can try changing the color instead (if you make the fillcolor = to the background color the stimulus disappear), and if you can’t try searching the forum for a solution.

tandy