"attempt to call a nil value" No Stack Trace

It’s probably the least descriptive error you can get from ROBLOX Studio. It occurs when you use :connect() without a valid function (or nil), but not when you call :connect(); it only shows the error after the event has fired at least once (all times after that, the error does not assert). The error contains no stack trace, not even the script that caused the error. That’s a problem.

How to reproduce:

  1. In a Script, call connect() of any object’s Event and give it a nil function. Example: connecting the Touched event of a button but misspelling the given function name (so it’s nil).
  2. Fire the Event and the Output gives the nondescript error of “attempt to call a nil value”. The Output does not provide a stack trace, not even the script in question.

Suggested solutions:

  • Have :connect() error if a function is not given as soon as it is called, not after the event fires. In other words, actually check the first damn argument when it’s called.
  • Have the error to the output actually give the script in question, not just “attempt to call a nil value”. When ScriptContext’s Error event is fired, the script is given there.

Temporary Workarounds:

  • Use a plugin to connect to ScriptContext’s Error event. If an error message is “attempt to call a nil value”, then give the script in question. Here’s some working code:
game:GetService("ScriptContext").Error:connect(function (message, trace, script)
	if message == "attempt to call a nil value" and script then
		game:GetService("TestService"):Message(script:GetFullName() .. " - " .. message)
	end
end)
9 Likes

There are a few stackless errors I don’t know the cause of, however this is the most infamous and annoying.

5 Likes

Yeah, those vague errors are quite annoying.

4 Likes

This bug is a duplicate of the following bug on GitHub: RBXScriptSignal.connect does not verify argument type.

2 Likes