Tween:Clone() does not preserve the Tween’s Instance. A cloned Tween’s Instance will always be nil instead of the Tween’s original Instance. The clone becomes useless since Instance is a read-only property and therefore cannot be set again.
Code example
local TweenService = game:GetService("TweenService")
--// Create a part
local part = Instance.new("Part", workspace)
part.Anchored = true
--// Create a tween
local tween = TweenService:Create(
part,
TweenInfo.new(),
{Position = Vector3.one}
)
--// Clone the tween
local clone = tween:Clone()
print(tween.Instance) -- Part
print(clone.Instance) -- nil
Recreating the tween through TweenService:Create() works around this, but it doesn’t resolve the unexpected cloning behaviour. Is this an intentional limitation of Tween cloning?
I’m not 100% sure I follow - is the intended workflow to clone these tweens on the same instance and then you modify them?
To be clear: I believe you are correct that Instance cloning doesn’t work on tweens. But my instinct would be to disable it, not to attempt to fix it, since a lot of tween configuration is constructor-only.
The one potential useful workflow for cloning Tweens (if they could be cloned properly) is to use each Completed event for connecting different functions. This is the only case I can think of since the properties of Tweens are read-only. However, this could still be accomplished by using :Create() for the same Tween multiple times.
Example:
local TweenService = game:GetService("TweenService")
--// Create a part
local part = Instance.new("Part", workspace)
part.Anchored = true
--// Create a tween
local tween = TweenService:Create(
part,
TweenInfo.new(),
{Position = Vector3.one}
)
--// Functions
function foo(): ()
print("foo")
end
function bar(): ()
print("bar")
end
--// Clone and connect functions
local clone = tween:Clone()
tween.Completed:Connect(foo)
clone.Completed:Connect(bar)
--// Play tweens
tween:Play()
task.delay(5, clone.Play, clone)
I thought it was worth a bug report since this behavior isn’t listed anywhere in the documentation. Disabling cloning of Tweens would be a fine fix for this since the only use is extremely situational and probably not worth the effort of fixing.