Cannot resume dead coroutine despite it being a new coroutine

ScanProcess should be specifically checked if it is not nil.
It will proceed to close the coroutine if you don’t check for nil because ScanProcess can also be false.

local ScanProcess = nil
function ButtonPressed()
    if ScanProcess ~= nil then
        coroutine.close(ScanProcess)
    end

    ScanProcess = coroutine.create(Scan)
    coroutine.resume(ScanProcess)
end

Other than that, I’d check for some similar information here:

1 Like