краш скрипта

Zеro

Известный
Автор темы
92
30
Версия SA-MP
  1. 0.3.7 (R1)
после одной ведёной команды скрипт умирает и в мунлоге выдает ошибку
Reconnect.lua: attempt to call a nil value
stack traceback:
Reconnect.lua: Script died due to an error. (0E132B3C)
где косяк в коде

Lua:
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do
    wait(200)
    end
    sampAddChatMessage('Загружен.', -1)
    sampRegisterChatCommand("rec", rec)
    sampRegisterChatCommand("recn", recn)
    while true do
        wait(0)
        if recon and time ~= nil then
            sampDisconnectWithReason(quit)
            wait(time*1000) -- установка 1 секи если не указано время
            sampSetGamestate(1)
            recon = false
            else if res and time == nil then
                sampDisconnectWithReason(quit)
                wait(0)
                sampSetGamestate(1)
                recon = false
            end
        end
    end
end

function reс(param)
    time = tonumber(param)
    recon = true
end

 function recn(param)
   local rname = string.match(param, '%s*(.+)')
   if rname ~= nil then
    sampSetLocalPlayerName(rname)
    recon = true
   else
    sampAddChatMessage("Рекон со сменой ника  /recn NickName ", -1)
   end
 end