Hi, I made some lines of code dealing with TweenService, however, I’m not getting the results I need. Why?
What do you want to achieve? Working TweenService animation.
What is the issue? The first Tween animation works, but the second Tween animation doesn’t.
What solutions have you tried so far? Tried the Tween.Completed function. Still didn’t work, they even started trying to overlap each other.
Alright so, putting it simple, it’s like the script is having a seizure trying to figure out when these animations need to play. With the Tween.Completed function, the animations literally started overlapping each other. With this current code I have down below, the second animation (“tween 2”) is completely being overlooked, and I have no idea why. If you can help me, or have any tips, please tell me them.
local G = script.Parent
local LeftHand = G["Left Hand"].Hand
local RightHand = G["Right Hand"].Hand
local TweenService = game:GetService("TweenService")
local OGPosition = Vector3.new(17.661, 101.609, 240.776)
local OGOrientation = Vector3.new(18.61, -153.729, 54.64)
task.wait(2)
for i = 1, math.huge do
print("Starting")
local Goal = {}
Goal.Position = Vector3.new(18.281, 97.064, 240.776)
Goal.Orientation = Vector3.new(12.937, -150.687, 65.784)
local Tween = TweenService:Create(RightHand, TweenInfo.new(2.5, Enum.EasingStyle.Linear), Goal)
Tween:Play()
print("Playing...")
task.wait(2.5)
local Goal2 = {}
Goal2.Position = Vector3.new(OGPosition)
Goal2.Orientation = Vector3.new(OGOrientation)
local Tween2 = TweenService:Create(RightHand, TweenInfo.new(0.5, Enum.EasingStyle.Linear), Goal2)
Tween2:Play()
print("Playing... No. 2")
end
You can also do this for your second tween as well to wait until it finishes. Tweens can get a little sketchy when you have 2 tweens on the same Instance(RightHand) like you do.
You are not waiting for the second tween to finish. First tween overwrites second tween as soon as it is started. Put wait after playing the second tween, or even better, as quakage said, tween2.Completed:Wait().
Also it is better to declare and create constant objects outside of loop, for performance reasons.
local Goal = {
Position = Vector3.new(18.281, 97.064, 240.776),
Orientation = Vector3.new(12.937, -150.687, 65.784),
}
local Tween = TweenService:Create(RightHand, TweenInfo.new(2.5, Enum.EasingStyle.Linear), Goal)
local Goal2 = {
Position = Vector3.new(OGPosition)
Orientation = Vector3.new(OGOrientation)
}
local Tween2 = TweenService:Create(RightHand, TweenInfo.new(0.5, Enum.EasingStyle.Linear), Goal2)
for i = 1, math.huge do
print("Starting")
Tween:Play()
print("Playing...")
Tween.Completed:Wait()
Tween2:Play()
print("Playing... No. 2")
Tween2.Completed:Wait()
end
Finally consider learning and using CFrames, as with Position and Orientation You can only tween single parts and not assemblies.
Thanks to the both of you. I really appreciate this. For some reason, the “Solution” box isn’t working and instead I’m getting greeted with an error code. So, sorry about that.