Why isn't NumberValue working?

It is printing “Error”
DigitalOn.Value I have set to 1, I am not sure why it’s not working…

local Bleachers = {}
local function FindBleacherParts(obj)
	for _, child in pairs(obj:GetDescendants()) do
		if child:IsA("BasePart") then
			table.insert(Bleachers,child)
		end
		FindBleacherParts(child)
	end
end
FindBleacherParts(workspace.Bleachers)

local function OnClick()
	if script.Parent.Parent.DigitalOn.Value==1 then
		local TweenService = game:GetService("TweenService")
		local tweenInfo = TweenInfo.new(5)
		local bleacher1=Bleachers[1]
		local FilmOn1 = 
			{
				Size = Vector3.new(5.531, 0.045, 240.227),
				Position = Vector3.new(bleacher1.CFrame.X, bleacher1.CFrame.Y+ 10.521, bleacher1.CFrame.Z)
			}
		local tween1 = TweenService:Create(bleacher1, tweenInfo, FilmOn1)
		tween1:Play()
		local bleacher2=Bleachers[2]
		local FilmOn2 = 
			{
				Size = Vector3.new(5.531, 0.045, 240.227),
				Position = Vector3.new(bleacher2.CFrame.X, bleacher2.CFrame.Y- 10.521, bleacher2.CFrame.Z)
			}
		local tween2 = TweenService:Create(bleacher2, tweenInfo, FilmOn2)
		tween2:Play()
		wait(5)
		script.Parent.Parent.DigitalOn.Value=0
	else if script.Parent.Parent.DigitalOn.Value==0 then
			print("Can not change aspect ratio right now.")
	        else print("Error")		
		end
	end
end


script.Parent.ClickDetector.MouseClick:Connect(OnClick)

it seems that something is going wrong with the line:
if script.Parent.Parent.DigitalOn.Value==1 then

Even though, it is set at 1…
image

It looks like the NumberValue’s name is “Value”, correct?
Writing script.Parent.Parent.DigitalOn.Value just gets the NumberValue itself.
In order to get the actual value of the NumberValue (or any other ObjectValue), you need to write NumberValue.Value. So, in this case, try if script.Parent.Parent.DigitalOn.Value.Value==1.

3 Likes

Follow the hierarchy being described by that line of code. Is the Value actually located there?

no it would be value.parent.folder

value.parent == script.parent.parent

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