Attempt to call a nil value

This is the most painful error I’ve ever gotten.

It’s been like this for a while, I’ve put it to the side but finally decided to tackle the error today. I’ve ran over this code like 4 times looking for spelling errors, issues with strings etc, nothing is working.

This one script keeps throwing “attempt to call a nil value” with 0 trace, I did some research and people are saying its a misspelling in the strings which clearly isn’t the case here. I’ve decided to ask you guys and see what you think, here’s the long code (sorry for that)

I am 100000% the issue comes from this script as every other script works, to be sure I used this 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)

To check and it pointed me to the exact script

Regards,
Void

1 Like

It would be better if you tell us where (in what line) is the error.

1 Like

It doesn’t have a line, no source or link to click on. So I can’t really. I’ve tried finding the line but none of that worked.

The error can even be in line 3. Try looking again on the code and items that you have (I mean that you have to check if you have for example “oof” event in Replicated Storage and right spelled “oof” event in Script).

Here's some info about nil error:

The nil error is usually caused when:

  • setting something to something that does not exist
  • trying to use wrong value (for example string instead of int).
2 Likes

I went over every single line again, I changed anything with “Fire” to ‘Fire’ and checked all the lines I think would have the error, still nothing. All my spelling is correct, I have no clue what’s wrong with this at this point.

Still going

It can’t because he’s not calling anything in line 3, and he would be getting a stack trace.

The error is occurring inside of either a coroutine or a pcall, otherwise you would be getting a stack trace. The error you’re looking for will likely be a misspelt function name (Like pritn() or math.aocs()) that is not an Instance method (Such as Part:Destoy() or Sound:play()) as a misspelt Instance method will throw a different error.
It is possible it is more than a typo though, but this is the first thing to look for.

Rework the script temporarily and remove pcalls and coroutines so you can see the stack trace. Or throw a ton of prints in there to see exactly which line it stops on.

1 Like

Thanks very much for that, I’ve located the error, now gotta figure out what’s wrong

		if math.acos((v.Position - sprinkler.Emitter.Position).Unit:Dot(Vector3.new(0, -1, 0))) < math.rad(45) and fire then print("28")
					coroutine.wrap(function() print("29")
						fire.Size = 30 print("30")

It printed 27, (code before), threw the error then printed 31

The error can be in line 3. I meant a “valid” error in line 3.

Good solution. Prints would always help you. I didn’t think about that.

So this shouldn’t be the problem, but did you know that in that vicinity you failed to capitalize Size in fire.Size?

Also, if you wouldn’t mind, could you upload the full script as it currently is (with all of the prints) and the full output including the prints and the errors?

My apologies, all the Sizes are now capitalized, unfortunately I removed all the print statements already but here’s the script

The line with the error has it noted down, at the start of the coroutine I printed from there all the way down 40 lines till the fire:Destroy()

It stopped printing at 27, then threw the “attempt to call a nil value” and then printed 31 as seen here below:

if math.acos((v.Position - sprinkler.Emitter.Position).Unit:Dot(Vector3.new(0, -1, 0))) < math.rad(45) and fire then print("28")
					coroutine.wrap(function() print("29")
						fire.Size = 30 print("30")

Well I’m either doing something wrong or right, because not only can I not see the error in your code, but it runs fine for me. Baseplate - Roblox
Feel free to open that up in Studio.
I changed all of the Sprinklers from Models to Parts for simplicity for setup, used only a single sound for every effect, and restructured the code so that both manual and automatic activations are the same function (Though it was working prior to that as well)
I changed the math for the fire.Size because it would make my campfire into a bonfire, but it worked before all of that as well. Oh, and I removed an unnecessary coroutine, but it didn’t change anything and worked just fine when it was still there.

Did it throw the attempt to call a nil value error? If not, can I see the updated code please.

Never mind, just tested on your game, I could edit it, found the script and I’m configuring it to my system now, I’ll let you know if I get anything

Just got this problem and the solution:

image

The cause for this is calling a nil value using the delay() method: the problem will happen by doing this:

delay(3, <null>)

For me the fix was changing
image

To this:

image

(callback was nil)

1 Like

There is no such thing if it says, “Attempt to call a nil value”

1 Like

This is happening to me too```