CanterCrow
(CanterCrow)
January 25, 2021, 8:57am
#1
I am trying to get each tween running after each other, I have a working script below is this a good way of doing it?
local tweenStatus = Instance.new(“IntValue”)
GuiObject = script.Parent.Parent.Frame
function tweenComplete ()
tweenStatus.Value = tweenStatus.Value + 1
end
tweenStatus.Changed:Connect(function(NewValue)
if NewValue == 1 then
GuiObject:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1, false, tweenComplete)
end
if NewValue == 2 then
GuiObject:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1, false, tweenComplete)
end
end)
tweenStatus.Value = 1
1 Like
vBaRaAx02
(vBaRaAx02)
January 25, 2021, 9:28am
#2
Can’t you just use wait
with the duration you set for each tween?
1 Like
CanterCrow
(CanterCrow)
January 25, 2021, 10:44am
#3
Hi, Yes I could but I want each tween to be smooth as moving to GUI in different directions and would look odd if the paused due to lag.
I am always looking for the optimal way of coding.
Julian
1 Like
kylerzong
(kylerzong)
January 25, 2021, 10:55am
#4
GuiObject = script.Parent.Parent.Frame
GuiObject:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1, false, function()
GuiObject:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 1, false)
end)
1 Like
CanterCrow
(CanterCrow)
January 25, 2021, 11:09am
#5
Hi, thanks for the code, so the second tween is in tween complete so will only run once the first has completed?
This is great and very clean.
Regards
1 Like
Here’s another way you can do it that also works with other instances that don’t have TweenPosition:
local tween1 = TweenService:Create(instance, tweenInfo1, propertyTable1) --fill this out
local tween2 = TweenService:Create(instance, tweenInfo2, propertyTable2) --fill this out
tween1:Play()
tween1.Completed:Wait()
tween2:Play()
You also won’t end up with many nested anonymous functions if you want to play like 10 tweens in sequence.