Why don't the lights change?

Hi,
I want to script a traffic light. However, my script doesn’t work the way it should. However, my script doesn’t work the way it should. The light /decals should react to the Nuber Value in NumVal. The light /decals should react to the Nuber Value in NumVal. However, they don’t. I used a clickdetector for testing, which sets the NumVal from 1 to 2. You can find the scripts below.

function changeLight()
	local rot = script.Parent.Rot
	local orange = script.Parent.Orange
	local gruen = script.Parent.Gruen
	local Value = script.Parent.NumVal.Value
	wait()
	if Value == 1 then
		rot.Decal.Transparency = 0
		rot.PointLight.Enabled = true
		orange.Decal.Transparency = 1
		orange.PointLight.Enabled = false
		gruen.Decal.Transparency = 1
		gruen.PointLight.Enabled = false
	elseif Value == 2 then
		rot.Decal.Transparency = 0
		rot.PointLight.Enabled = true
		orange.Decal.Transparency = 0
		orange.PointLight.Enabled = true
		gruen.Decal.Transparency = 1
		gruen.PointLight.Enabled = false
	elseif Value == 3 then
		rot.Decal.Transparency = 1
		rot.PointLight.Enabled = false
		orange.Decal.Transparency = 1
		orange.PointLight.Enabled = false
		gruen.Decal.Transparency = 0
		gruen.PointLight.Enabled = true
	elseif Value == 4 then
		rot.Decal.Transparency = 1
		rot.PointLight.Enabled = false
		orange.Decal.Transparency = 0
		orange.PointLight.Enabled = true
		gruen.Decal.Transparency = 1
		gruen.PointLight.Enabled = false
	end
end

script.Parent.NumVal:GetAttributeChangedSignal("Value"):Connect(changeLight())

Script from the traffic lights.

local Value = script.Parent.Parent.Parent.NumVal.Value

script.Parent.MouseClick:Connect(function()
	Value = 2
	print(Value)
end)

Script from the Button. The button shouldn’t have an error.
Thank you for your help
Pino

1 Like

You’re setting Value equal to the current value of NumVal. If you want to change NumVal’s value, do

local NumVal = script.Parent.Parent.Parent.NumVal

script.Parent.MouseClick:Connect(function()
    NumVal.Value = 2
end)
1 Like

try this?

function changeLight()
	local rot = script.Parent.Rot
	local orange = script.Parent.Orange
	local gruen = script.Parent.Gruen
	local Value = script.Parent.NumVal.Value
	wait()
	if Value == 1 then
		rot.Decal.Transparency = 0
		rot.PointLight.Enabled = true
		orange.Decal.Transparency = 1
		orange.PointLight.Enabled = false
		gruen.Decal.Transparency = 1
		gruen.PointLight.Enabled = false
	elseif Value == 2 then
		rot.Decal.Transparency = 0
		rot.PointLight.Enabled = true
		orange.Decal.Transparency = 0
		orange.PointLight.Enabled = true
		gruen.Decal.Transparency = 1
		gruen.PointLight.Enabled = false
	elseif Value == 3 then
		rot.Decal.Transparency = 1
		rot.PointLight.Enabled = false
		orange.Decal.Transparency = 1
		orange.PointLight.Enabled = false
		gruen.Decal.Transparency = 0
		gruen.PointLight.Enabled = true
	elseif Value == 4 then
		rot.Decal.Transparency = 1
		rot.PointLight.Enabled = false
		orange.Decal.Transparency = 0
		orange.PointLight.Enabled = true
		gruen.Decal.Transparency = 1
		gruen.PointLight.Enabled = false
	end
end

script.Parent.NumVal:GetAttributeChangedSignal("Value"):Connect(changeLight)

Script from the traffic lights.

local Val= script.Parent.Parent.Parent.NumVal

script.Parent.MouseClick:Connect(function()
	Val.Value = 2
	print(Value)
end)
1 Like

unfortunately it doesn’t work :frowning:

1 Like

Don’t you mean

script.Parent.NumVal:GetPropertyChangedSignal("Value"):Connect(changeLight)

I think I accidentally replied to the wrong person, @PinoRisi03 this is for you

1 Like

Thank you for your help :slight_smile:

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like