It's a bit difficult to debug without being able to run the script and reproduce the issue. Please see the guidelines for
posting Vizard code as this will make it easier for others to help debug.
One thing you could try is to replace:
Code:
vizact.ontimer2(2, 0, end_el_recording, participant_id, block_num, trial)
with a viztask.waitTime() command that yields for 2 seconds and then calls the function. This will prevent later lines of code in the task function from executing until the two seconds has elapsed.