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.
Missing keywords or brackets
Section titled “Missing keywords or brackets”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!")endUnexpected nil
Section titled “Unexpected nil”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.")endCalling the wrong value
Section titled “Calling the wrong value”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.
Wrong types
Section titled “Wrong types”"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: 120Conditions that behave strangely
Section titled “Conditions that behave strangely”- Use
==to compare values;=assigns them. - Use
~=for “not equal”, not!=. 0and""are truthy. Checkhealth > 0ortext ~= ""when that is what you mean.condition and first or secondchoosessecondiffirstisfalseornil.
A loop does not finish
Section titled “A loop does not finish”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.