Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why do my tweens glitch when trying to fire multiple at once?

Asked by 3 years ago
Edited 3 years ago

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?

https://imgur.com/99e72Mv

0
might be your tweening the animations too fast, so when it starts, its starting a new one? this is a comment because im not so sure.. jasperagent 43 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

0
If a tween has already begun calling Play will have no effect unless the tween has finished or has been stopped (either by TweenBase:Cancel or TweenBase:Pause) as said by the documentation. In any case, what happens when I try to wait until it's completed is: Script timeout: exhausted allowed execution time meaning that sometimes it completely doesn't fire at all and hangs Studio...  RekkSai 0 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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.

Answer this question