Last active
September 21, 2021 23:03
-
-
Save lucasmz-dev/9e90a58b73efe83679f35224f9f574f9 to your computer and use it in GitHub Desktop.
QuickTween
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local TweenService: TweenService = game:GetService("TweenService") | |
local FreeThread: thread? = nil | |
local function DestroyTween(tween: Tween) | |
local thread = FreeThread :: thread | |
FreeThread = nil | |
while true do | |
tween.Completed:Wait() | |
tween:Destroy() | |
FreeThread = thread | |
tween = coroutine.yield() :: Tween | |
end | |
end | |
return function( | |
instance: Instance, | |
tweenInfo: TweenInfo, | |
properties: any | |
): Tween | |
assert( | |
typeof(instance) == 'Instance', | |
"Must be an instance" | |
) | |
assert( | |
typeof(tweenInfo) == 'TweenInfo', | |
"Must be TweenInfo" | |
) | |
assert( | |
typeof(properties) == 'table', | |
"Must be a table" | |
) | |
local tween: Tween = TweenService:Create(instance, tweenInfo, properties) | |
tween:Play() | |
if FreeThread == nil then | |
FreeThread = coroutine.create(DestroyTween) :: thread | |
end | |
task.spawn(FreeThread :: thread, tween) | |
return tween | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment