MethodTween - a library for tweening object methods, with 1-to-1 parity to TweenService

Introduction

MethodTween allows you to animate non-tweenable properties such as Scale & CFrames of models, through an API that aims to replicate Roblox’s by as much as possible. The implementation includes support for reversing, delays, repeats & different tweening styles and directions.

How to Use

Due to the getter & setter methods being separate & using separate namings (e.g., GetPivot() and PivotTo, or GetScale & ScaleTo), each field accepts an array of two values; the start and end value to tween to-and-fro, like so:

MethodTween.new(Object, TweenInfo.new(...), {
    ScaleTo = {0.5, 1} -- Start from 0.5 and end at 1
}):Play()

Outside of the differing property tables, the rest of the API behaves exactly the same as Roblox’s - it runs every Stepped, supports methods such as :Cancel() & :Pause(), and has a PlaybackState variable to describe it’s current state. It additionally has a Completed event.

Observers

If you feel the library doesn’t allow you to do enough, or want to add custom behavior on top, you can use Observers.
Simply put, observers allow you to listen to the alpha value each frame, like so:

local Tween = MethodTween.new(Part, TweenInfo.new(1), {})

local id = Tween:Observe(function(Alpha)
	print(Alpha)
end)

Tween:Play()

task.wait(0.5)
Tween:StopObserving(id)

Installation

The module is available both on wally & on Roblox:

Misc.

The source can be found on my GitHub.

25 Likes

Wow, this is a godsend, so many times in my life have I had to tween an entire model. This makes it way easier, and there’s no new API to learn!

Will definitely be including this in our framework packages along with your packet size measure module.

2 Likes

v1.1.0

  • Allow new tweens to override existing/already-playing ones
  • Fix Enum.PlaybackState not being set to Playing if DelayTime parameter of TweenInfo was used
1 Like

v1.1.1

1 Like

v1.1.3

  • Fix wally packaging
1 Like

v1.2.0

  • Fix packaging
  • Implement minimal Observer pattern. Added methods :Observe(callback -> alpha) -> id and :StopObserving(id).
1 Like

v1.2.1

  • Fix Wally packaging not working. This is only relevant to people who have installed this module with Wally.
1 Like

Is there a preview of this module or no?

v1.2.2

  • Fix tweens being delayed by one frame when running with TweenInfo.DelayTime == 0

Currently working on a complicated skill for my game, it’s very vfx based and required a lot of tweening of general things. THIS IS A LIFE SAVER MAN.
DEMO:
robloxapp-20240511-1323044.wmv (2.7 MB)

1 Like

What does this line do? I’m trying to set a CFrame during the tween and this line is breaking the module. It’s effectively doing:

part["CFrame"](part, newValue)

which doesn’t make any sense. I get the error “attempt to call a CFrame value”, so I effectively can’t use this module to tween CFrame

edit: I see what it does now, but I’m still not sure how to use CFrame on ordinary parts with this module

It calls methods; so you should be using PivotTo instead of setting the CFrame. Like so:

MethodTween.new(Object, TweenInfo.new(...), {
    PivotTo = {
        Object:GetPivot(), TargetCFrame
    }
}):Play()