Skip to content

Instantly share code, notes, and snippets.

@lucasmz-dev
Last active September 21, 2021 23:03
Show Gist options
  • Save lucasmz-dev/9e90a58b73efe83679f35224f9f574f9 to your computer and use it in GitHub Desktop.
Save lucasmz-dev/9e90a58b73efe83679f35224f9f574f9 to your computer and use it in GitHub Desktop.
QuickTween
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