Attempt to index nil with 'value'

I’m not sure why I’m getting this error. “Point” is defines as either Value1 or Value2, which are names of NumberValues.

game.ReplicatedStorage.CalVotes.OnServerEvent:Connect(function(point)
	local value = game.ReplicatedStorage:FindFirstChild(point)
	wait(.1)
	value.value = value.value + 1
	wait(.1)
	print(value.value)
end)
1 Like

FindFirstChild() checks if the value exists or not. Use WaitForChild() if you want to ensure the child exists.

If you change that line, it might work. An example could be:

local value = game.ReplicatedStorage:WaitForChild(point)

Also, if that doesn’t work, it could be because the Value property of the item is spelt with a capital V, but in the script you have referenced it with a lower case .value. Try changing that as well.

2 Likes

I’m pretty sure even if “value” is not nil since your calling “.value” instead of “.Value” as @12345koip said it will throw an error. Make sure before you check if the object your indexing is nil, check if what your calling on the Object is an actual thing(if that makes sense)

2 Likes

Always keep in mind that Luau is case sensitive, remember this especially when modifying a property of something,
it should be:
value.Value = value.Value + 1
or make it shorter if you want
value.Value += 1

2 Likes

I changed both those and the error is gone, but it’s still not changing the value

How would I check that? I have both the values set to 0 and it’s in the script to set them to 0 at the beginning of the game too, but I can’t get the values to increase

Does it print 0 when your print “value.Value” ? make sure your saying “value.Value” since if you are indexing value with a lower case v it will print nothing or nil and wont error.

Yeah I changed it to lowercase and the error’s gone, but it doesn’t print anything when it runs

It could be that the variable name is too similar to the property name Value. Try changing the variable name to point.
So, the first line would change to:

point = game.ReplicatedStorage:WaitForChild(point)

What does it say when you print the actual object instead of the objects value?

still nothing. and no errors either

Is there anything in the Output regarding ‘Infinite Yeild’?

yeah it just came up when it was run

the first parameter of OnServerEvent is the player who fired it, try game.ReplicatedStorage.CalVotes.OnServerEvent:Connect(function(plr,point). also FindFirstChild and WaitForChild use strings as the parameter, so it won’t work if you put an instance in there.

So how would I find it without using FindFirstChild or WaitForChild? ‘point’ is defined as a name of a NumberValue

That means WaitForChild() is waiting forever. Check the variable you are passing down the RemoteEvent, because right now it is set as "Instance."

This therefore means that the code will wait for something that won’t actually exist.

1 Like

if point is the name of a NumberValue then it’s a string, so the problem is with how you set up your parameters.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.