Is it possible to start a tween at a specified timestamp?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I would like to start a tween at a specified timestamp

  2. What is the issue? Include screenshots / videos if possible!
    I’m tweening something on the client that I want to sync up to the server, this could sync up at any time, the easing style is not linear, so it’s not like I can just change the length of the tween to whatever’s left.

I’m not tweening on the server because that would cost a lot of performance having to replicate every update each frame, so using the clients to tween and the server sending the end goal would be a lot better.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve searched everywhere online, I can’t find a topic even discussing it, also tried custom tweening scripts, but they are a lot less performant than Roblox’s C# TweenService.
1 Like

:Play() the tween whenever something is triggered.

1 Like

:Play() will play the tween from the start, which is not what I’m looking for

I’m not always playing from 0.5, random values so this won’t work, I’m also using quad not sine

You can use TweenService:GetValue to tween from a custom starting and ending point:

local TweenService = game:GetService("TweenService")

-- duration of the tween
local duration = 3

-- where you want the tween to start/stop
-- from 0 to 1 normally
local startTime = 0.3
local finishTime = 1

-- part to tween or whatever
local obj =

-- where you want the value to tween to/from
-- can be any data type
local startValue = Vector3.new(0, 0, 0)
local finishValue = Vector3.new(0, 0, 1)


local adjustedLength = finishTime - startTime
local i = 0
while i < 1 do
    local dt = task.wait()

    i = math.min(i + dt/duration, 1)

    -- transform from [0, 1] to [startTime, endTime]
    local preAlpha = i * adjustedLength + startTime

    local alpha = TweenService:GetValue(
        preAlpha,
        Enum.EasingStyle.Quad,
        Enum.EasingDirection.Out
    )

    -- transform from [startTime, endTime] to [0, 1]
    local postAlpha = (alpha - startTime) / adjustedLength

    -- apply `postAlpha` to a lerping function
    obj.Position = startValue:Lerp(finishValue, postAlpha)
end

Edit: This would actually lead to the value jumping up to wherever 0.3 is, oops
Edit 2: It should be fixed :+1:
Edit 3: should actually be fixed
Edit 4: should actually be fixed [2]

I would like to note that it would be difficult to make a tween-like interface for this, but it’s still possible anyway.

I suppose it can be made simpler with coroutines:

local function partialTween(...)
    -- code up there I guess
end

-- when you want the tween to start
local tweenThread = task.spawn(
    partialTween,
    -- cool arguments
)

-- when you want the tween to stop
task.cancel(tweenThread)
4 Likes