I am trying to use multiple tweens to have incoming GUI objects at the same time like in guitar hero for example.
tweenService = game:GetService("TweenService") for i = 1, 220, 1 do b = Instance.new("TextLabel") b.Parent = script.Parent b.Size = UDim2.new(0, 50, 0, 50) b.Position = UDim2.new(0, 0, 0, 300) b.BorderSizePixel = 0 b.Visible = true local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In) local tween = tweenService:Create(b, tweenInfo, {Position = UDim2.new(0, 600, 0, 300)}) tween:Play() tween.Completed:Connect(function() b:Destroy() end) wait(.3) end
When using this script, the tween system starts glitching and Completed either fires too early or doesn't fire at all for some. What do you think is the problem?
The script looks completely fine but it seems that when you run it the notes are being deleted before they are being tweened to its target position. This may be because the script does not wait until the gui is tweened successfully so i suggest addin this into your scrip to confirm that it reaches its target position:
tweenService = game:GetService("TweenService") for i = 1, 220, 1 do b = Instance.new("TextLabel") b.Parent = script.Parent b.Size = UDim2.new(0, 50, 0, 50) b.Position = UDim2.new(0, 0, 0, 300) b.BorderSizePixel = 0 b.Visible = true local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In) local tween = tweenService:Create(b, tweenInfo, {Position = UDim2.new(0, 600, 0, 300)}) repeat tween:Play() until b.position = UDim2.new(0, 0, 0, 300) tween.Completed:Connect(function() b:Destroy() end) wait(.3) end
However, i am not 100% sure this is the case, but nevertheless, try this script out, it repeats tween:Play() until the gui reaches its target position!
Any Questions? Just ask!
I have solved this.
For future reference. I made a queue data structure and put the "b" labels in. And as the Completed events were fired, I would remove from the back of the queue. That prevented the system from getting confused and removing ones that just spawned. So instead I would just remove the oldest one. The problem was that since the code doesn't wait for the tween to finish, it goes to the next iteration and therefore loses the pointer to the "b" from previous iterations. The faster the loop the more of them get left behind and "Completed" triggering means only new ones get removed on tween events from old completed iterations.
Hope this makes sense.