[DEPRECATED] Tween module: may or may not make tweening faster

THIS MODULE HAS BEEN DEPRECATED AND SHOULD NOT BE USED. IT WILL NO LONGER RECIEVE UPDATES AND IS MOSTLY USELESS. I’VE LEFT THIS UP FOR ARCHIVING PURPOSES

I know there’s better alternatives but i decided to post this anyways. This module is just making tweening easier, and i think it can be very useful.


Module link: https://create.roblox.com/marketplace/asset/13822792949


Methods:
Tween: based on your current arguments it will create a tween.


Arguments:

  • Target (instance): your instance that you want to tween

  • Seconds (string/number): the amount of seconds the tween lasts

  • Goal (dictionary, like in regular tweens): it’s the property (Like {Transparency = 1})

  • Play (boolean, optional argument):
    true or nil will automatically play the tween
    false won’t do anything

  • DestroyTween (boolean, optional argument):
    true or nil will do CreatedTween.Completed:Once(function() CreatedTween:Destroy() end)

  • Easingstyle (Enum.EasingStyle, optional): your EasingStyle

  • EasingDirection (Enum.EasingDirection, optional): your EasingDirection
    (if EasingDirection or EasingStyle are nil then it will default to Linear and Out)


MODELS ARE NOT SUPPORTED!


Here’s my code if you don’t want to open it in a place:

local TweenModule = {}
function TweenModule.Tween(Target, Seconds, Goal, Play, DestroyTween, Easingstyle, Easingdirection)
	local TweenService = game:GetService("TweenService")
	local TweenInfoVar = TweenInfo.new(Seconds,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out
	)
	if Easingstyle ~= nil and Easingdirection ~= nil then
		print(Easingstyle, Easingdirection)
		local TweenInfoVar = TweenInfo.new(Seconds,
			Easingstyle,
			Easingdirection
		)
	elseif Easingstyle == 3 then --these are just my prefered tweening settings, nothing to see here lol
		print(Easingstyle, Easingdirection)
		local TweenInfoVar = TweenInfo.new(Seconds,
			Enum.EasingStyle.Sine,
			Enum.EasingDirection.Out
		)
	end
	local CreatedTween = TweenService:Create(Target, TweenInfoVar, Goal)
	if Play == true or Play == nil then
		CreatedTween:Play()
	elseif typeof(Play) ~= "boolean" and Play ~= nil then
		error("Tween expects the last argument to be a boolean or nil, got ".. tostring(Play))	
	end	
	if DestroyTween == true or DestroyTween == nil then
		CreatedTween.Completed:Once(function()
			CreatedTween:Destroy()
		end)
	elseif DestroyTween == false then
		TweenModule.CreatedTween = CreatedTween
	elseif typeof(DestroyTween) == "boolean" and DestroyTween ~= nil then
		error("Tween expects the last argument to be a boolean or nil, got ".. tostring(Play))	
	end
end
return TweenModule
1 Like

Could you add color tweening? I don’t see why I would just manually tween if it doesn’t support things like color tweening, transparency tweening, etc.

What do you mean? Pretty sure it supports that unless i had an oversight. Goal is a custom argument that is specifically made for that. So the goal argument would be {Color = Color3.fromRGB()}
Yeah I’m pretty sure you misinterpreted unless I’m stupid lol. Don’t worry.
Goal is just like the last argument of TweenService:Create()

1 Like

I thought tweenservice didn’t support goal colors. If you are just rerouting the commands to TS. I will have to test it tho

1 Like

It supports every property type (nearly) that isn’t read only. Examples of non-working ones: BrickColor: can replace with Color
TimeOfDay (the one with the 24 hour format like 00:00) which can be replaced with ClockTime (uses regular numbers like 1 which is 1 PM or 13) and materials for obvious reasons.

1 Like

definitely not a life saver, just a extension of tweenservice that is generally worse in most aspects

1 Like

there are way too many arguments for a simple tween function (also why not use tweeninfo?), why do this

local goal = { Transparency = 1 }

TweenModule.Tween(workspace.Baseplate, 10, goal, true, false, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

TweenModule.Tween(
  workspace.Baseplate, 
  10, 
  goal, 
  true, 
  false, 
  Enum.EasingStyle.Sine, 
  Enum.EasingDirection.Out
)

when you can do this?

local tweenInfo = TweenInfo.new(10, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local goal = { Transparency = 1 }

-- ...
local t1 = TweenService:Create(workspace.Baseplate, tweenInfo, goal)
local t2 = TweenService:Create(workspace.Baseplate, tweenInfo, goal) -- reusing the tweenInfo

t1:Play()
t2:Play()

your method is slightly unreadable compared to the traditional method, unless you store the arguments as variables; and suggestion: if there is only 1 function in a module, then its better to return the function itself

local tween = require(...)

tween(...) -- less verbose

edit: this is what i usually use for tweens:

local TweenService = game:GetService('TweenService')

return function(info: TweenInfo, property: {[string]: any})
	return function(instance: Instance)
		local tween = TweenService:Create(instance, info, property)
		
		tween:Play()
		
		return tween
	end
end
local createTween = require(...)

local tween = createTween(TweenInfo.new(1), { Size = Vector3.one * 2 })

tween(workspace.Baseplate)
1 Like

Well i thought it’d be easier for some since in reality all you need is a target, amount of seconds, goal and the rest is optional. It saves you a couple of seconds of feeling the tween or whatever. It comes down to personal preference.
I’m probably gonna update it to make it a bit easier to use and Tweeninfo support

1 Like

No offense, but I really don’t get the point of this module. Tweens are already destroyed automatically by the garbage collector so there’s no reason to manually destroy them most of the time

that part is for people who do it. i have seen people want to do it.