Tween not repeating properly

for i, child in pairs(script.Parent:GetChildren()) do
	
	if child.ClassName == "ImageLabel" then
		
		--create tween
		local info = TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1)
		local introInfo = TweenInfo.new(SPEED, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
		local goal = {Position = UDim2.new(0, 0, 0, 0)}
		local introGoal = {Position = UDim2.new(-1, 0, 0, 0)}
		local tween = tweenServ:Create(child, info, goal)
		local introTween = tweenServ:Create(child, introInfo, introGoal)
		
		child:GetPropertyChangedSignal("Visible"):Connect(function()
			
			if child.Visible then
				
				child.Position = UDim2.new(-2, 0, 0, 0)
				introTween:Play()
				print("waiting")
				introTween.Completed:Wait()
				print("ready")
				tween:Play()
				print("done")
				
			else
				
				tween:Pause()
				
			end
			
		end)
		
	end
	
end

I have this rigged up so that every time a different script makes this banner visible, it will start an animation.
However, it doesn’t loop properly. I want it to come in from the left, and then play a new tween going to the right, and looping that repeatedly so it looks like an endless loop, almost like an endless “stream” but from the left side of the screen.
It works the first time, but never again. The print statements print as well. It gets right up to the tween statement, and even prints the line after it.
Why isn’t it playing?

1 Like

Try making the tween inside the child:GetPropertyChangedSignal("Visible"):Connect(function()
I’m not too sure though, do reach back :slight_smile:

2 Likes

Ok, so this did work. For some reason it feels like it should, but I don’t really understand why it works like this and not like before. Hopefully somebody will come along and explain it.

2 Likes

Ok so I think you are making the tween once, and making the tween every time inside the signal makes it make a new one. The new one can be tweened to your purpose. The one above the signal would count as a “local” variable used in global context inside the signal at any time.
Hope that makes kinda sense :slight_smile:

EDIT:
from what I see above maybe you should use tween:Cancel() in the else statement too maybe that might work?
idk you do you :slight_smile:

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