Scripts

Error parsing script (Lua syntax error)

The file is not valid Lua, so the whole script fails to load. Often habits from JavaScript or C#.

The error
Error parsing script @my_script/server.lua: unexpected symbol near '!'

Common mistakes

  • != instead of ~=
  • // comments instead of --
  • && and || instead of and and or
  • A missing then, do or end
  • A missing comma between table entries

Example

Lua
-- Wrong
if job != 'police' && onDuty {
    // notify
}

-- Right
if job ~= 'police' and onDuty then
    -- notify
end

How to fix it

  1. Go to the line in the error. The real mistake is often one or two lines above it.
  2. Use an editor with Lua support (VS Code with the Lua extension) to see errors while you type.
  3. If you use Lua 5.4 features such as <const>, add lua54 'yes' to the manifest.