From 4edaddf1516f5fb93fb1421d69d8280c2420f419 Mon Sep 17 00:00:00 2001 From: sindri <33976067+isarsindri@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:53:49 +0100 Subject: [PATCH] Update tween.luau fix test fail again! yes i'm a retard --- src/tween.luau | 65 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/src/tween.luau b/src/tween.luau index 403785d..2d6657c 100644 --- a/src/tween.luau +++ b/src/tween.luau @@ -1,47 +1,62 @@ -- src/tween.luau local TweenService = game and game:GetService("TweenService") or nil -local HasTweenInfo = (TweenInfo ~= nil) +local HasTweenInfo = (TweenInfo ~= nil) + +--cleanup and action injection so tweens are stopped on scope destruction --- Factory: inject action + cleanup so tweens are stopped on scope destruction return function(action, cleanup) local tween = {} - -- Presets (simple, useful) + -- Presets: only available when TweenInfo exists (Roblox runtime) if HasTweenInfo then - tween.presets = { - instant = TweenInfo.new(0), - fast = TweenInfo.new(0.12, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), - smooth = TweenInfo.new(0.22, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), - snappy = TweenInfo.new(0.16, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), - } + tween.presets = { + instant = TweenInfo.new(0), + fast = TweenInfo.new(0.12, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), + smooth = TweenInfo.new(0.22, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), + snappy = TweenInfo.new(0.16, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), + } + else + tween.presets = {} + end - -- Imperative helper (for events): vide.tweenTo(instance, {Position=...}, info) + -- Imperative helper: plays a tween (or applies instantly in tests) function tween.tweenTo(instance, goals, info) + if not instance or not goals then + return nil + end + + -- Non-Roblox / unit tests: apply instantly if not TweenService then - -- Non-Roblox / tests: just apply instantly - if instance and goals then - for k, v in pairs(goals) do - instance[k] = v - end + for k, v in pairs(goals) do + instance[k] = v end return nil end - local tweenInfo = info or tween.presets.smooth + + local tweenInfo = info + if tweenInfo == nil then + if tween.presets.smooth then + tweenInfo = tween.presets.smooth + else + -- Fallback in case presets are not available for any reason + tweenInfo = TweenInfo.new(0.22, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) + end + end + local tw = TweenService:Create(instance, tweenInfo, goals) tw:Play() return tw end - -- Action helper (for create trees): - -- create "Frame" { tween({Position=...}, presets.fast), ... } + -- Action helper: attach tweening in create() trees function tween.tween(goals, info) return action(function(instance) if not goals then return end - -- If TweenService not available, apply instantly (tests outside of roblox environment) + -- Non-Roblox / unit tests: apply instantly if not TweenService then for k, v in pairs(goals) do instance[k] = v @@ -49,11 +64,19 @@ return function(action, cleanup) return end - local tweenInfo = info or tween.presets.smooth + local tweenInfo = info + if tweenInfo == nil then + if tween.presets.smooth then + tweenInfo = tween.presets.smooth + else + tweenInfo = TweenInfo.new(0.22, Enum.EasingStyle.Quad, Enum.EasingDirection.Out) + end + end + local tw = TweenService:Create(instance, tweenInfo, goals) tw:Play() - -- Stop on scope destruction to avoid leaking connections/tweens + -- Ensure tween is cancelled when the scope is destroyed cleanup(function() pcall(function() tw:Cancel()