GetAttributeChangedSignal does not work

Well, my script is changing a value, and the other part of the script should detect that change, applying it to TweenInfo.new, causing the speed of a TweenService to change, but it simply does not detect it and it does not change the speed of the tweenService.

local TweenService = game:GetService("TweenService")
local ColorEffect = Instance.new("ColorCorrectionEffect")
ColorEffect.Parent = game:GetService("Lighting")

while true do
	wait(3)
	script.Value.Value += 0.1
end

script.Value:GetAttributeChangedSignal("Value"):Connect(function()
	local tweenInfo = TweenInfo.new(script.Value.Value)
	local tween1 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = -2})
	local tween2 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = 0})
	print("no")
	while true do
		tween1:Play()
		wait(0.2)
		tween2:Play()
		wait(0.2)
		print("si")
	end
end)

Code does not run after a while loop. Put the while loop below the GetAttributeChangedSignal event

1 Like
script.Value:GetAttributeChangedSignal("Value"):Connect(function()
	local tweenInfo = TweenInfo.new(script.Value.Value)
	local tween1 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = -2})
	local tween2 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = 0})
	print("no")
	while true do
		tween1:Play()
		wait(0.2)
		tween2:Play()
		wait(0.2)
		print("si")
	end
end)

while true do
	wait(3)
	script.Value.Value += 0.1
end

Like so

1 Like

Do this:

local TweenService = game:GetService("TweenService")
local ColorEffect = Instance.new("ColorCorrectionEffect")
ColorEffect.Parent = game:GetService("Lighting")
local Loop = coroutine.wrap(function()
 while true do
	 wait(3)
	 script.Value.Value += 0.1
 end
end)

Loop()
script.Value:GetAttributeChangedSignal("Value"):Connect(function()
	local tweenInfo = TweenInfo.new(script.Value.Value)
	local tween1 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = -2})
	local tween2 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = 0})
	print("no")
	while true do
		tween1:Play()
		wait(0.2)
		tween2:Play()
		wait(0.2)
		print("si")
	end
end)
1 Like

Also your value shouldn’t be named “Value” because that can cause some problems

1 Like

It should be fine for this script as the script does not have a Value property.

2 Likes

There are way more issues than the code being under a while loop

  • Why are you using GetAttributeChangedSignal on a property? It should be GetPropertyChangedSignal

  • There’s going to be overlapping while loops for everytime the value changes, so the tweening will look weird

I think you can just use another while loop for what is needed

local TweenService = game:GetService("TweenService")
local ColorEffect = Instance.new("ColorCorrectionEffect")
ColorEffect.Parent = game:GetService("Lighting")

coroutine.wrap(function()
	while true do
		local tweenInfo = TweenInfo.new(script.Value.Value)
		local tween1 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = -2})
		local tween2 = TweenService:Create(ColorEffect, tweenInfo, {Saturation = 0})
	
		tween1:Play()
		wait(0.2)
		tween2:Play()
		wait(0.2)
		print("si")
	end
end)()

while true do
	wait(3)
	script.Value.Value += 0.1
end

This way when it needs to play tweens again, it’lls make them corressponding to the current value

Also not sure if you should change the wait time to waiting for the tween to finish since the more it increases, the more the tweens will overlap

1 Like