How to add Delaytime to tween to make it wait then reverse

local ts = game:GetService("TweenService")
local part = script.Parent
local repeatdo = 0

local Info = TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.In,1231312213312321331231231312321313123,true,10)

local goals = {

	Position = Vector3.new(242.885, -573.734, -917.707);

}

local tweenTrack = ts:Create(part,Info,goals)


	tweenTrack:Play()

I want to add a delay time for when it reaches the destination, I want it to wait for a few seconds before reversing.

I do not want new code, I just want my code but with the new improvements.

Just use the code you wrote, it should work

No, it does not work. The tween reverses itself immediately after reaching the destination.

Oh wait I think I get it. Delay time in the tween info is only for the delay before it starts, so if you want to make a delay, consider this code:

local ts = game:GetService("TweenService")
local part = script.Parent
local waitTime = 10 --set your wait time here

local Info = TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.In)

local tweenTrack = ts:Create(part,Info,{Position = Vector3.new(242.885, -573.734, -917.707)})
local tweenTrack2 = ts:Create(part,Info,{Position = part.Position})

tweenTrack.Completed:Connect(function()
    task.wait(waitTime)
    tweenTrack2:Play()
end)
tweenTrack2.Completed:Connect(function()
    task.wait(waitTime)
    tweenTrack:Play()
end)
tweenTrack:Play()

If it worked, please set it as the new solution so others can see it too :slight_smile:

Sadly, it does not work. The part goes to random directions and does not function as intended.

Can you send a vid of what happens?

Also, if you would like infinite tweens, set this to -1.

1 Like

Try this:

local ts = game:GetService("TweenService")
local part = script.Parent
local waitTime = 10 --set your wait time here

local Info = TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.In)

local tweenTrack = ts:Create(part,Info,{Position = Vector3.new(242.885, -573.734, -917.707)})
local tweenTrack2 = ts:Create(part,Info,{Position = Vector3.new(part.Position.X,part.Position.Y,part.Position.Z})

tweenTrack.Completed:Connect(function()
    task.wait(waitTime)
    tweenTrack2:Play()
end)
tweenTrack2.Completed:Connect(function()
    task.wait(waitTime)
    tweenTrack:Play()
end)
tweenTrack:Play()

Make sure that your part is anchored

1 Like

Still breaks, the floor and anything welded to it go in opposite directions.

Vid for anybody who wants to see the problem

This is what happens with John_15051’s code

So the floor is disconnecting and you want it to stay with it?

What’s wrong with the train in the video? I thought you wanted a part to move to a position, wait, then return toi ts original position, wait again, and repeat. That’s what the code I gave you does. If that is not what you’re trying to achieve, then what is?

Edit: You can adjust the waitTime variable to change how long the tween waits before repeating again. In the code I posted, it was set to ten seconds and I could see that the video you sent wasn’t even ten seconds long. Either wait for ten seconds to see if it works or just reduce it to something like one second.

Edit2: I just realized when testing out the code that a parenthesis was missing ;-; you should have noticed it in the output dude. Here’s the new code:

local ts = game:GetService("TweenService")
local part = script.Parent
local waitTime = 1 --set your wait time here

local Info = TweenInfo.new(10,Enum.EasingStyle.Sine,Enum.EasingDirection.In)

local tweenTrack = ts:Create(part,Info,{Position = Vector3.new(447, 0.5, 3965)})
local tweenTrack2 = ts:Create(part,Info,{Position = Vector3.new(part.Position.X,part.Position.Y,part.Position.Z)})

tweenTrack.Completed:Connect(function()
	task.wait(waitTime)
	tweenTrack2:Play()
end)
tweenTrack2.Completed:Connect(function()
	task.wait(waitTime)
	tweenTrack:Play()
end)
tweenTrack:Play()

Just one extra parenthesis

1 Like

This is how it looks like with the exact code I sent above.

Delay time = 1
Tween time = 10

1 Like

Within TweenInfo there is a Parameter that allows you to set a Delay for the Tween, if you need a Quick rundown of that the parameters are:

TweenInfo.new(
    1,                          -- Duration
    Enum.EasingStyle.Linear,    -- EasingStyle
    Enum.EasingDirection.InOut, -- EasingDirection
    0,                          -- Times Repeated?
    true,                       -- Reversed?
    2,                          -- Delay?
)

It Honestly seems like a Waste of time to wait for a Tween to Finish using Completed just to fire another Tween, when you can just have one Tween, and a Parameter do it for you.

I found out the issue. The welds corrupted. Thanks man.

He tried it but it didn’t work, because the delay is only for the start of the tween and not between the repetition of the tween. He wants a delay both at the start and when it is about to repeat.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.