Skip to content

Common Errors

When something goes wrong, start with the filename and line number in the error message. The actual mistake may be just before that line, such as a missing quote or end.

if needs then and end. A function needs end, and a for or while loop needs do and end. A repeat loop ends with until condition instead.

Also check that every (, {, and quote has a matching closing character. Indentation makes missing endings easier to spot:

local fps = 120
if fps >= 60 then
lh.drawln("Smooth!")
end

Errors mentioning arithmetic, concatenation, or indexing a nil value usually mean a value is missing. Check spelling, capitalization, and scope.

local playerName = "iFair"
lh.drawln(playerName) -- Use the same spelling and capitalization.

For an optional value, check before using it:

local name = nil
if name ~= nil then
lh.drawln("Hello, " .. name)
else
lh.drawln("No name available.")
end

An error about calling a nil, string, or number means the value before () is not a function. Check the function’s name and whether you accidentally overwrote it.

When passing a callback, use the function itself, as shown in Functions.

"120" is a string; 120 is a number. Use tonumber() for numeric text and check whether it returns nil. Use tostring() before joining a boolean or nil to text.

To inspect a value temporarily:

local value = "120"
lh.drawln("Type: " .. type(value) .. ", value: " .. tostring(value))
-- Output: Type: string, value: 120
  • Use == to compare values; = assigns them.
  • Use ~= for “not equal”, not !=.
  • 0 and "" are truthy. Check health > 0 or text ~= "" when that is what you mean.
  • condition and first or second chooses second if first is false or nil.

Check that its counter changes and its stopping condition can be reached. To run code on later ticks, register a callback instead of waiting in a loop.

Try a small example first, then add the rest back a little at a time. Once these basics make sense, continue to Drawing Your First HUD.