Attempt to index nil with 'Value'

I tried referencing a value that is inside the localscript but it just doesnt work and I dont know whats the problem.

I get th error: “Workspace.IvanThGreat64.DashScript:19: attempt to index nil with ‘Value’”

local charge = script:FindFirstChildWhichIsA(“Value”)

task.spawn(function()
while true do
if charge.Value < 3 then
charge.Value = charge.Value + 1
else
charge.Value = charge.Value
end
wait(3)
end
end)

Help would be appreciated.

local charge = script:FindFirstChildWhichIsA(“Value”)

You need to specify what value type,

Which like said below me, in your case would be a Integer Value or Number value which can be referred to as
local charge = script:FindFirstChildWhichIsA(“IntValue”) or local charge = script:FindFirstChildWhichIsA(“NumberValue”)

Value is not a type of Instance, use Basevalue, or in your case, just do

local charge = script:FindFirstChildOfClass("IntValue")
1 Like

That might work, but I replaced script:FindFirstChildWhichIsA(“Value”) with script:WaitForChild(“Value”)
which seemed to work fine aswell.

That’ll work probably because the name of the Value “instance” is “Value”. However if it was not, it wouldn’t work in this case, it’d just infinitely yield.

With WaitForChild() you’re waiting for a child with the name of the string you have in the function.

1 Like
local charge = script:WaitForChild("Value")

Luau is an event driven programming language. You should be utilising the Value's ‘Changed’ event/signal.

https://developer.roblox.com/en-us/api-reference/event/IntValue/Changed