hi guys, I wrote a function to tween a model. How optimized is my code? And is it worth using this instead of roblox physics (weld)?
local TweenService = game:GetService('TweenService')
local function TweenModel<A>(model, Goal: CFrame, time, ES, ED, callback: ((A...) -> ())?, ...: A...)
ES = ES or Enum.EasingStyle.Linear
ED = ED or Enum.EasingDirection.In
local start = model:GetPivot()
local tick_end = os.clock() + time
coroutine.wrap(function(...)
while task.wait() do
local t = (tick_end - os.clock()) / tick_end
model:PivotTo(start:Lerp(goal, TweenService:GetValue(math.min(t, 1), ES, ED))
if t >= 1 then break end
end
if callback then callback(...) end
end)(...)
end