Coroutines affecting future loops

I’ve been trying to make a little gui easter egg with some snow particles. I created a basic frame and a loop which tweens its transparency and position to the bottom
image
However after a few seconds of running and the coroutines that were supposed to change a certain particle’s transparency to 1 before deleting it are changing newly made particles’ transparencies.
Here’s a simplified version of the loop

while true do
	wait(.15)
	local snowp = particle:Clone()
	--assume particle has a set random position
    --tween vars do what their names say
	local co = coroutine.create(function()
		movetween:Play()
		appeartween:Play()
		--disappeartween:Play()
        --this tween seems to be flooding into the following loops and
        --affecting future particle clones for some reason
		wait(10)
		snowp:Destroy()
	end)
	coroutine.resume(co)
end

I tried to use the delay parameter in TweenInfo, and also just tried wait a few seconds after the initial 2 tweens have played and then play disappeartween, but it still leaks in following loops.
Are there any suggestions? I’m honestly just stuck and don’t know what to do. Not incorporating that tween works out ok, but it would be nice if I could actually make it work

2 Likes

Where are the tweens being declared, as they require the instance to be passed in as their first argument?

1 Like

The tweens are declared right when the loop starts, tweeninfo is declared before this loop starts

1 Like

Ok so it looks like this :

 --declare tweeninfos
while true do
  task.wait(0.15)
  --clonepart
  --declare new tweens
  --create new coroutine to run tweens
  --resume coroutine
end

It could be a scope issue caused by declaring tweens outside of the coroutine so as the loop ends and restarts it’s picking up new info.
I would try moving the clone and tween creation inside the coroutine just to make sure.

Try using Completed on the tweens it yields until the tweens have played

movetween:Play()
appeartween:Play()
movetween.Completed:Wait()
appeartween.Completed:Wait()
disappeartween:Play()
disappeartween.Completed:Wait()
--task.wait(10 - length of 3 tweens) (if you want to keep it after disappearing) 
snowp:Destroy()