Tween Doesn't Play

Hello,

I have created a script which tweens a UI to make it disseapear/reapear when you go to a certain area, but currently it doesn’t work. The code is as follows:

local PlazaEvent = script.Parent
local PlazaRemote = game.ReplicatedStorage.Plaza


UIStart = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
UIEnd = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
TextTransparency = game.StarterGui.NewAreas.AreaUI.TextTransparency

UIeventStart = game:GetService("TweenService"):Create(AreaUI, UIStart, {transparency = 0})
UIeventEnd = game:GetService("TweenService"):Create(AreaUI, UIEnd, {transparency = 1})
print("got past code")

AreaUI = game.StarterGui.NewAreas.AreaUI

while true do
	UIeventStart:Play()
	UIeventEnd:Play()
	print("looped!!!")
	wait(0.1)
end
1 Like

:Play() doesn’t yield on tween objects. We could rewire your code structure to perform the same purpose as your loop but with built-in events on the tween objects, like so-

UIeventStart:Play()

UIeventStart.Completed:Connect(function()
UIeventEnd:Play()
end)

UIeventEnd.Completed:Connect(function()
UIeventStart:Play()
end)

And then you can call the :Cancel() method on those tween objects as needed.

3 Likes

At the end, it looks like you are playing both tweens every 0.1 seconds. If a new tween is played that is for the same property, it will stop the 1st tween. So the “Start” tween is started, then the “End” tween is immediately started, cancelling the 1st tween.

1 Like

Yep, just realized that now. Thanks for helping though!

1 Like

That should fix the wait too. Thanks alot!

1 Like