How to reset a Tween?

local tweenService = game:GetService(‘TweenService’)

local Down = workspace.down

local Properties = {

Position = Vector3.new(game.ReplicatedStorage.Position.Value,Down.P.CFrame.Y,Down.P.CFrame.Z)

}

local TweenInformatiton = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)

local tween = tweenService:Create(Down.P,TweenInformatiton,Properties)

wait(3)

tween:Play()

game.ReplicatedStorage.Position.Value = game.ReplicatedStorage.Position.Value +20

tween:Reset()

wait(3)

tween:Play()

What do you mean by this? You can also use triple backticks to make code more easy to read. [ ``` ]

As in how do you replay a tween after it ends

To reset a tween use Tween:Cancel() then Tween:Start(). This doesn’t reset the original state of the object though, it only resets the Tween.

To reset the state of the original object, you would need to store it then reset it yourself:

local TweenService = game:GetService(‘TweenService’)

local Down = workspace.down

local originalPosition = Down.P.Position

local properties =
{Position = Vector3.new(game.ReplicatedStorage.Position.Value, originalPosition.Y, originalPosition.Z)}
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tween = TweenService:Create(Down.P, tweenInfo, properties)

wait(3)
tween:Play()
game.ReplicatedStorage.Position.Value = game.ReplicatedStorage.Position.Value + 20
Down.P.Position = originalPosition --tween:Reset()
wait(3)
tween:Play()
1 Like

You cant really “reset” a tween but when a tween finished you can change its properties back to what it was before the tween started.


local InitalPos = Part.Position

--CreateTween
--TweenPart to New position

wait(3)

Part.Position  = InitalPosition--Set the parts position back to where it was before the tween
2 Likes

I’m assuming to what you said, you can do this.

local tweenService = game:GetService(‘TweenService’)

local Down = workspace.down

local Properties = {

Position = Vector3.new(game.ReplicatedStorage.Position.Value,Down.P.CFrame.Y,Down.P.CFrame.Z)

}

local TweenInformatiton = TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,5,false,0)

local tween = tweenService:Create(Down.P,TweenInformatiton,Properties)

wait(3)

tween:Play()

game.ReplicatedStorage.Position.Value = game.ReplicatedStorage.Position.Value +20

tween:Reset()

wait(3)

tween:Play()

For the 12th line, at the end, you can put the number of times the tween replays, if the tween can be reversed, and the delay of seconds.

-- For the (5,false,0), The first 5 means how many times the tween repeats.
-- For the "false", it means if the tween will just teleport back to original position and repeat the tween, however, if set to "true", it will smoothly repeat backwards to its original position and property and repeat the tween again.

-- For the 0 (last value), it means how long the tween will delay.
-- // So in this case, the product will be below.

-- \\ Tween repeats 5 times by teleporting and reverting back to original position, (no delays). // --

TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,5,false,0)

(p.s: you can use math.huge for the number of times it gets repeated. (math.huge is infinite)

How would I move it to another posititon?

Because I’m running it off a custom admin command

If you want to move it to another position each time you run the tween, you could store the position in a variable, or a list of positions to tween to.

1 Like