Axolotleless

KeyframeSequence player edited

Aug 14th, 2025 (edited)
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.51 KB | None | 0 0
  1. local TS = game:GetService("TweenService")
  2. local runservice = game:GetService("RunService")
  3.  
  4. local tStyle, tDirection = {
  5. [Enum.PoseEasingStyle.Linear]    = Enum.EasingStyle.Linear;
  6. [Enum.PoseEasingStyle.Bounce]    = Enum.EasingStyle.Bounce;
  7. [Enum.PoseEasingStyle.Cubic]    = Enum.EasingStyle.Cubic;
  8. [Enum.PoseEasingStyle.Elastic]    = Enum.EasingStyle.Elastic;
  9. [Enum.PoseEasingStyle.Constant]    = Enum.EasingStyle.Linear;
  10. },{
  11. [Enum.PoseEasingDirection.In]    = Enum.EasingDirection.In;
  12. [Enum.PoseEasingDirection.Out]    = Enum.EasingDirection.Out;
  13. [Enum.PoseEasingDirection.InOut]= Enum.EasingDirection.InOut;
  14. }
  15.  
  16. function PlayKeyframeSequence(Model, KeyFrameSequence, SpeedMult)
  17.     local AllKeyFrames = {}
  18.    
  19.     for i,Keyframe in pairs(KeyFrameSequence:GetKeyframes()) do
  20.         table.insert(AllKeyFrames, {
  21.         Time = Keyframe.Time,
  22.         Keyframe = Keyframe
  23.         })
  24.     end
  25.     table.sort(AllKeyFrames, function(a, b)
  26.         return a.Time < b.Time
  27.     end)
  28.    
  29.     local tweens = {}
  30.     local motors = {}
  31.     local motorValues = {}
  32.     local KeyFramePoses = {}
  33.    
  34.     local function GetMotorFromPose(Pose, Keyframe)
  35.         local FullName = Pose:GetFullName()
  36.         local Path = string.split(FullName, ".")
  37.         local KFPosition = table.find(Path, Keyframe.Keyframe.Name)
  38.        
  39.         for i,v in pairs(Model:GetDescendants()) do
  40.             if v:IsA("Motor6D") and v.Part1.Name == Pose.Name and v.Part0.Name == Pose.Parent.Name then
  41.                 return v
  42.             end
  43.         end
  44.         return nil
  45.     end
  46.    
  47.    
  48.     for i,Keyframe in pairs(AllKeyFrames) do
  49.         for x,Pose in pairs(Keyframe.Keyframe:GetDescendants()) do
  50.             if Pose:IsA("Pose") and Pose.Weight>0 then
  51.                 local Motor6D = motors[Pose.Name] or GetMotorFromPose(Pose, Keyframe)
  52.                 if not KeyFramePoses[i] then
  53.                     KeyFramePoses[i] = {
  54.                     Time = Keyframe.Time,
  55.                     Poses = {}
  56.                     }
  57.                 end
  58.                 if not motors[Pose.Name] then
  59.                     motors[Pose.Name] = Motor6D
  60.                 end
  61.                 if not motorValues[Pose.Name] then
  62.                     local motorVal = Instance.new("CFrameValue")
  63.                     motorVal.Name = "MotorValue"
  64.                     motorVal.Parent = motors[Pose.Name]
  65.                     motorValues[Pose.Name] = motorVal
  66.                 end
  67.                
  68.                 if Motor6D then
  69.                     KeyFramePoses[i].Poses[Pose.Name] = {Motor6D = Motor6D, Pose = Pose}
  70.                 end
  71.             end
  72.         end
  73.     end
  74.    
  75.     if #KeyFramePoses-1>0 then
  76.         print(KeyFramePoses)
  77.         local lastPose = {}
  78.         for i in ipairs(KeyFramePoses) do
  79.             if i == #KeyFramePoses then break end
  80.            
  81.             local KF1, KF2 = KeyFramePoses[i], KeyFramePoses[i+1]
  82.             local t = KF2.Time-KF1.Time
  83.            
  84.             tweens[i] = {
  85.             Time = t,
  86.             Tweens = {}
  87.             }
  88.             print(KF1.Time,KF2.Time)
  89.             for name,data in pairs(KF1.Poses) do
  90.                 lastPose[name] = data
  91.             end
  92.             for name,data in pairs(KF2.Poses) do
  93.                 --print(name,i)
  94.                 --print(lastPose,lastPose[name])
  95.                 local tweeninfo = TweenInfo.new(
  96.                 math.abs(lastPose[name].Pose:FindFirstAncestorOfClass("Keyframe").Time-KF2.Time),
  97.                 tStyle[lastPose[name].Pose.EasingStyle],
  98.                 tDirection[lastPose[name].Pose.EasingDirection]
  99.                 )
  100.                 tweens[i].Tweens[name] = TS:Create(motorValues[name],tweeninfo,{Value=data.Pose.CFrame})
  101.             end
  102.         end
  103.     end
  104.    
  105.     local function getLenght()
  106.         return KeyFramePoses[#KeyFramePoses].Time
  107.     end
  108.     local function play()
  109.         for i,v in pairs(tweens) do
  110.             --print(v.Time)
  111.             for x,tween in pairs(v.Tweens) do
  112.                 tween:Play()
  113.             end
  114.             task.wait(v.Time)
  115.         end
  116.     end
  117.    
  118.     runservice.Heartbeat:Connect(function()
  119.         for i,v in pairs(motors) do
  120.             --print(motorValues[i].Value)
  121.             v.Transform = motorValues[i].Value
  122.         end
  123.     end)
  124.    
  125.     while true do
  126.         task.wait()
  127.         if game.Workspace.Playing.Value == true then
  128.             play()
  129.         end
  130.     end
  131. end
  132.  
  133. PlayKeyframeSequence(script.Parent,workspace.R6.Run3)--edit the second part to the location of your KeyframeSequence
  134.  
Advertisement
Add Comment
Please, Sign In to add comment