local runService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
return function(character: Model,keyframeSequence: KeyframeSequence)
local transform: {{weld: Weld,default: CFrame}} = {}
local transformAmount = 0
local finished = 0
for _,joint in ipairs(character:GetDescendants()) do
if joint:IsA("Motor6D") then
local newweld = Instance.new("Weld")
newweld.Name = joint.Name .. "Weld"
newweld.Parent = joint.Parent
newweld.Part0 = joint.Part0
newweld.Part1 = joint.Part1
newweld.C0 = joint.C0
newweld.C1 = joint.C1
table.insert(transform,{
weld = newweld,
default = newweld.C0
})
end
end
for _ in transform do
transformAmount += 1
end
local keyframes: {Keyframe} = keyframeSequence:GetKeyframes()
table.sort(keyframes,function(a,b)
return a.Time < b.Time
end)
local currentIndex = 1
local nextIndex = 2
task.spawn(function()
while task.wait() do
currentIndex += 1
nextIndex += 1
local tweens: {Tween} = {}
local dTime = 0.5
for _,motor in ipairs(transform) do
local currentKeyframe = keyframes[currentIndex]
local nextKeyframe = keyframes[nextIndex]
if not nextKeyframe then continue end
local currentPose: Pose = currentKeyframe:FindFirstChild(motor.weld.Part1.Name,true)
if not currentPose then continue end
local nextPose: Pose = currentKeyframe:FindFirstChild(motor.weld.Part1.Name,true)
if not nextPose then continue end
local tweenInfo = TweenInfo.new(
dTime,
Enum.EasingStyle[currentPose.EasingStyle.Name],
Enum.EasingDirection[currentPose.EasingDirection.Name]
)
table.insert(
tweens,
tweenService:Create(
motor.weld,
tweenInfo,
{
C0 = motor.default * nextPose.CFrame
}
)
)
end
for _,tween in ipairs(tweens) do
tween:Play()
end
task.wait(dTime)
for _,tween in ipairs(tweens) do
tween:Destroy()
end
if currentIndex >= #keyframes then
currentIndex = 1
end
if nextIndex >= #keyframes then
nextIndex = 2
end
end
end)
end