An error occurred when using the attrited_control: set_offset_roll_pitch function in the LUA script

I want to use attritedself-control: set_offset_roll_pitch to control the aircraft’s attitude. I set up a simple program in the simulator, but it prompted an error.
The main error is on line 11, do you know the reason? Thank you.

function update () – periodic function that will be called
local current_pos = ahrs:get_position() – fetch the current position of the vehicle
local home = ahrs:get_home() – fetch the home position of the vehicle
if current_pos and home then – check that both a vehicle location, and home location are available
local distance = current_pos:get_distance(home) – calculate the distance from home in meters
if distance > 100 then – if more then 1000 meters away
distance = 100; – clamp the distance to 1000 meters
gcs:send_text(5, “>100”)

    local roll = math.deg(ahrs:get_roll())
    attitude_control:set_offset_roll_pitch(roll,30) -- Lua: ./scripts/2.lua:11: attempt to index a nil va
    gcs:send_text(5, "<99")


return update, 1000 -- request "update" to be rerun again 1000 milliseconds (1 second) from now


return update, 1000