in DaVinci Resolve this Lua script fails to create a compound clip, why is that?

-- Function to convert frames to timecode string
function framesToTimecode(frames, fps)
    local total_seconds = frames / fps
    local hours = math.floor(total_seconds / 3600)
    total_seconds = total_seconds % 3600
    local minutes = math.floor(total_seconds / 60)
    local seconds = math.floor(total_seconds % 60)
    local frame_number = math.floor(frames % fps)
    return string.format("%02d:%02d:%02d:%02d", hours, minutes, seconds, frame_number)
end

-- Initialize Resolve objects
local resolve = Resolve()
local projectManager = resolve:GetProjectManager()
local project = projectManager:GetCurrentProject()
local timeline = project:GetCurrentTimeline()
local markers = timeline:GetMarkers()

-- Get the frame rate
local timelineFps = tonumber(project:GetSetting("timelineFrameRate"))

if not timelineFps then
    print("Unable to retrieve timeline frame rate.")
    return
end

if not markers or next(markers) == nil then
    print("No markers found on the current timeline.")
    return
end

-- Loop through all markers
for frameId, marker in pairs(markers) do
    local start_frame = frameId
    local duration_frames = marker.duration

    if not duration_frames or duration_frames == 0 then
        print("Skipping marker '" .. (marker.name or "Unnamed") .. "' at frame " .. start_frame .. " with no duration.")
        goto continue
    end

    local end_frame = start_frame + duration_frames
    local name = marker.name or "Compound Clip"

    print("Processing marker '" .. name .. "' from frame " .. start_frame .. " to " .. end_frame)

    local itemsToInclude = {}
    local trackTypes = {"video", "audio"}  -- Process both video and audio tracks

    for _, trackType in ipairs(trackTypes) do
        local trackCount = timeline:GetTrackCount(trackType)
        for trackIndex = 1, trackCount do
            local clips = timeline:GetItemListInTrack(trackType, trackIndex)
            if clips then
                for _, clip in ipairs(clips) do
                    local clipStartFrame = clip:GetStart()
                    local clipEndFrame = clip:GetEnd()

                    if clipEndFrame > start_frame and clipStartFrame < end_frame then
                        -- The clip overlaps with the marker's range
                        table.insert(itemsToInclude, clip)
                    end
                end
            else
                print("No clips found in track " .. trackIndex .. " of type " .. trackType)
            end
        end
    end

    if #itemsToInclude == 0 then
        print("No clips found within marker range. Skipping marker '" .. name .. "'.")
        goto continue
    end

    -- Create compound clip from the list of timeline items
    local compoundClip = timeline:CreateCompoundClip(itemsToInclude)
    if compoundClip then
        -- Set the name of the compound clip
        local setNameResult = compoundClip:SetName(name)
        if not setNameResult then
            print("Failed to set name for compound clip.")
        else
            print("Compound clip '" .. name .. "' created.")
        end
    else
        print("Failed to create compound clip for marker: " .. name)
    end

    ::continue::
end