Stellar AI

Errors

FiveM/Lua: 'end' expected near <eof> – Fix

The error

SCRIPT ERROR: @my_resource/client.lua:88: 'end' expected (to close 'function' at line 40) near '<eof>'

What it means

This is a syntax error, so the whole file fails to load and nothing in it runs. Lua reached the end of the file (<eof>) while a block opened at the line given was still open. Every function, if ... then, for ... do and while ... do needs a matching end. A variant, unexpected symbol near 'end', means there is one end too many.

The fix

-- broken: the if block is never closed
CreateThread(function()
    while true do
        if IsControlJustPressed(0, 38) then
            print('E pressed')
        Wait(0)
    end
end)
-- fixed
CreateThread(function()
    while true do
        if IsControlJustPressed(0, 38) then
            print('E pressed')
        end
        Wait(0)
    end
end)

Start at the line number in brackets and check each block below it. An editor with Lua syntax checking (for example VS Code with a Lua extension) highlights the unclosed block.

Related errors

Related tools: FiveM script generator · Fix a FiveM Lua error · all script generators