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.

18 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

v1.1.1

v1.1.3

  • Fix wally packaging

v1.2.0

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