Operating Servo from the get_emergency_stop() function using Lua in QGC

So I’m trying to be able to detect whenever the emergency stop button is being pressed in QGC, and I saw in the documentation there was a SRV_Channels:get_emergency_stop() that would either return a true or false based on whether the command was run in QGC. When I try and implement it into my Lua script, QGC returns that the Lua script “gives bad result”. I will paste my code below if anyone has a solution to my issue that would be great.
local chan = 95 – Assuming channel 1 is the servo output channel you want to control

function update()
if SRV_Channels:get_emergency_stop() then
SRV_Channels:set_output_pwm(chan, 1900) – Set PWM to 1900 microseconds if emergency stop is true
– Set PWM to 1500 microseconds (neutral position) otherwise
end
return update, 100 – Return update function and delay of 100 milliseconds
end

return update, 1 – Initial return of update function and delay of 1 millisecond