Lua · Useful information

Errors and fixes

When a script throws an error it stops, and the message shows in a red box on its page. Fix the line and save: it starts again.

Reading an error

error
kill_feed.lua:27: attempt to index a nil value (local 'me')
  • kill_feed.lua is the file, 27 the line. Press Edit in the error box to open the script in the editor.
  • The text after the colon is what went wrong; the part in brackets names the variable.
  • Copy puts the whole error on the clipboard, ready to paste into an AI or a support chat.

Common errors

attempt to index a nil value

kills.lua:12: attempt to index a nil value (local 'me')

You used a field of something that is nil. game.local_player() is nil when you are dead, entity.* fields can be missing, bomb.state().pos is missing when unknown.

Fix
local me = game.local_player()
if not me then return end

attempt to call a nil value

hud.lua:5: attempt to call a nil value (field 'draw_text')

The function name is wrong (here draw.text), or it does not exist in this API. Check the spelling against the reference. os.*, io.* and require are not available.

Fix
draw.text(10, 10, "ok", white)

attempt to perform arithmetic on a nil value

bar.lua:20: attempt to perform arithmetic on a nil value (global 'kils')

A typo in a variable name, or a value that was never set. Globals that were never assigned are nil.

Fix
local kills = 0
kills = kills + 1

attempt to concatenate a nil value

feed.lua:9: attempt to concatenate a nil value (field 'victim')

.. cannot join nil. Use tostring(x) or (x or "").

Fix
print("killed " .. (e.victim or "?"))

attempt to compare number with nil

x.lua:4: attempt to compare number with nil

One side of < or > is nil, often ui.get with a wrong id.

Fix
local size = ui.get("size") or 16

bad argument #N to ...

bad argument #5 to 'text' (number expected, got nil)

You passed the wrong type. Here the colour was nil. Every colour must be an integer from color().

Fix
local white = color(255, 255, 255)
draw.text(10, 10, "hi", white)

script ran too long (infinite loop?)

script ran too long (infinite loop?)

One callback took more than 8 ms or 1 000 000 instructions. Look for a while loop that never ends, or heavy work every frame. Do it once and cache it, or spread it over several frames.

Fix
if not cache then cache = build() end

not enough memory

not enough memory

The script used its 64 MB. Usually a table that grows every frame and is never cleared.

Fix
if #log > 200 then table.remove(log, 1) end

unexpected symbol / 'end' expected

kills.lua:30: 'end' expected (to close 'function' at line 12) near <eof>

A syntax error. Every function, if, for and while needs its own end. The line number where Lua noticed can be far from the real mistake.

needs permission: settings

needs permission: settings, allow it on the script page

Not an error: the call returned false. Open the script's page and tick the permission under PERMISSIONS.

config.set: wrong type for ...

config.set: wrong type for aim.fov

The new value has a different type or shape than the setting. A colour is a table of 4 numbers from 0 to 1, a bool needs true/false.

Fix
config.set("aim.fov", 4.5)

config.set: unknown setting ...

config.set: unknown setting esp.boxcolor

The key does not exist. Keys are case-sensitive: esp.boxColor and esp.boxcolor are different. Check Settings keys.

http.get: only https://adolfjon.uz/ is allowed

http.get: only https://adolfjon.uz/ is allowed

Other websites are blocked on purpose.

image: not a PNG/JPG or larger than 2048x2048

image: not a PNG/JPG or larger than 2048x2048

Convert the file or make it smaller. WebP, GIF and SVG are not supported.

font: ... not found

font: myfont.ttf not found (data folder or Windows Fonts, .ttf/.otf)

Put the font in scripts/data/<script>/ or use one installed in Windows. Names are exact, for example segoeuib.ttf for Segoe UI Bold.

Debugging tips

  • print(json.encode(value)) shows what is inside a table.
  • Print once, not every frame: use a flag, or on_tick with a timer, or the console fills up.
  • Wrap risky code in pcall to keep the script running and log the error yourself:
pcall.lua
local ok, err = pcall(function()
    local data = json.decode(files.read("cfg.json") or "")
    print(data.name)
end)
if not ok then print("could not read cfg.json: " .. tostring(err)) end