Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to put a cooldown on Tween?

Hello!

I would like to know how I can put a timeout in the time that the block is to return to where it was.

when the interpolation ends at the indicated position when I activated the option "Reverse" (true) It does not wait for 1 second and returns to the position it was in. How can I make him wait a few seconds and then go back to where he was?

Script:

local Part1, Part2 = script.Parent.PartA, script.Parent.PartB;

local tweenInfo = TweenInfo.new(
	
	2,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	true,
	2
)



local a = TweenService:Create(Part1, tweenInfo, {Position = Vector3.new(81, 5, 197)})
local b = TweenService:Create(Part2, tweenInfo, {Position = Vector3.new(99, 5, 203)})

while wait()do
	
	a:Play()
	b:Play()
end

1 comment

0

use a wait(1)

1 answer

✓ Accepted answer

If you want the part to go back after a certain timeout, you will need to split tween to 2 separate tweens:

local Part1, Part2 = script.Parent.PartA, script.Parent.PartB;

local tweenTime = 2
local cooldown = 2

local tweenInfo = TweenInfo.new(

    tweenTime,
    Enum.EasingStyle.Linear

)


local aStartingPosition = Part1.Position
local bStartingPosition = Part2.Position
local a = TweenService:Create(Part1, tweenInfo, {Position = Vector3.new(81, 5, 197)})
local aReverse = TweenService:Create(Part1, tweenInfo, {Position = aStartingPosition})
local b = TweenService:Create(Part2, tweenInfo, {Position = Vector3.new(99, 5, 203)})
local bReverse = TweenService:Create(Part2, tweenInfo, {Position = bStartingPosition})

while wait() do

	a:Play()
	b:Play()

	wait(tweenTime + cooldown) 
	
	aReverse:Play()
	bReverse:Play()

	wait(tweenTime + cooldown)

end

Just remeber that playing a tween does not yield the thread, so you need to add tween time to cooldown time, before playing reverse tween.

This discussion is preserved as it was. New answers, comments, and votes are closed.