TweenService Issue

so i’m facing this weird issue with TweenService
the problem is, i’m making a Open/Close Tween and when it comes to the “closing” part the part doesn’t really go 5 studs below it does 10 studs instead, not sure why its doing that.

function test()

local Tween = game:GetService("TweenService")

local TweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0)

local Goal = {CFrame = script.Parent.CFrame + Vector3.new(0,5,0)}

local Goal2 = {CFrame = script.Parent.CFrame - Vector3.new(0,5,0)}

local TweenCreate = Tween:Create(script.Parent,TweenInfo,Goal)

local TweenCreate2 = Tween:Create(script.Parent,TweenInfo,Goal2)

TweenCreate:Play()
TweenCreate.Completed:Wait()
wait(1)
TweenCreate2:Play()
TweenCreate2.Completed:Wait()
test()
end
test()
1 Like

The problem is occuring because the “Goal” variable is created before any movement is done, so the “closing” movement actually just moves the door from its normal state to below the ground.

Creating the second tween after the first one is fully complete will fix the issue.

function test()

local Tween = game:GetService("TweenService")

local TweenInfo = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0)

local Goal = {CFrame = script.Parent.CFrame + Vector3.new(0,5,0)}
local TweenCreate = Tween:Create(script.Parent,TweenInfo,Goal)

TweenCreate:Play()
TweenCreate.Completed:Wait()
wait(1)
local TweenCreate2 = Tween:Create(script.Parent,TweenInfo,Goal2)
local Goal2 = {CFrame = script.Parent.CFrame - Vector3.new(0,5,0)}
TweenCreate2:Play()
TweenCreate2.Completed:Wait()
test()
end
test()
2 Likes
  1. Declare functions locally.
  2. Declare services at top of your script.
  3. Did you mean to call it inside itself or by accident?
  4. Use task.wait instead of wait ( more performant).
  5. No need to put a delay after tween.Completed:Wait(), that is already a delay.
  6. You should declare the second tween stuff once the first is finished.

Oops didnt mean to reply to you. But to the post creator.

2 Likes

oh i really didn’t realise that thanks anyways lol.
Goal & Goal2 are saving the same Part CFrame

Yes, when you create a variable it doesn’t dynamically update its value if you meant to reference it to something, so take that in consideration!

Also, check out those tips left above your post by @Valkyrop, they’ll help you write better code.

yeah as i said i already know that but i didnt literally realise it.
i already know @Valkyrop 's tips but i just did this for fun not for an actual project or smth so yeah.

1 Like