Advertisement
MoltenMeat

R6 Simplified Animate Script

Aug 12th, 2024 (edited)
1,215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | Source Code | 0 0
  1. local Character = script.Parent
  2. local Humanoid = Character:WaitForChild("Humanoid")
  3. local RootPart = Character:WaitForChild("HumanoidRootPart")
  4. local Animator = Humanoid:WaitForChild("Animator")
  5.  
  6. local currentAnim = ""
  7. local currentAnimTrack = nil
  8. local animationTable = {}
  9.  
  10. -- Preload animations
  11. local animations = {
  12.     -- here put your own anim iDs
  13.     idleAnimation = "http://www.roblox.com/asset/?id=180435571",
  14.     walkAnimation = "http://www.roblox.com/asset/?id=180426354",
  15.     jumpAnimation = "http://www.roblox.com/asset/?id=125750702",
  16.     fallAnimation = "http://www.roblox.com/asset/?id=180436148",
  17.     climbAnimation = "http://www.roblox.com/asset/?id=180436334",
  18.     sitAnimation = "http://www.roblox.com/asset/?id=178130996",
  19.    
  20.     -- you can add your own animations, remember that they should play when humanoid enters a certain state or situation
  21. }
  22.  
  23. for animName, animId in pairs(animations) do
  24.     local anim = Instance.new("Animation")
  25.     anim.AnimationId = animId
  26.     animationTable[animName] = anim
  27. end
  28.  
  29. -- Stop all animations
  30. local function StopAllAnimations()
  31.     if currentAnimTrack then
  32.         currentAnimTrack:Stop()
  33.         currentAnimTrack:Destroy()
  34.         currentAnimTrack = nil
  35.     end
  36. end
  37.  
  38. -- Play animation by name
  39. local function PlayAnimation(animName)
  40.     if animName == currentAnim then return end
  41.     StopAllAnimations()
  42.     currentAnim = animName
  43.     currentAnimTrack = Animator:LoadAnimation(animationTable[animName])
  44.     currentAnimTrack:Play()
  45. end
  46.  
  47. local function onSeated()
  48.     PlayAnimation("sitAnimation")
  49. end
  50.  
  51. -- Humanoid state change functions
  52. local function onJumping()
  53.     PlayAnimation("jumpAnimation")
  54. end
  55.  
  56. local function onClimbing(speed)
  57.     if math.abs(speed) > 0.2 then
  58.         if currentAnim ~= "climbAnimation" then
  59.             PlayAnimation("climbAnimation")
  60.         elseif currentAnimTrack then
  61.             currentAnimTrack:AdjustSpeed(1)
  62.         end
  63.     else
  64.         if currentAnimTrack then
  65.             currentAnimTrack:AdjustSpeed(0)
  66.         end
  67.     end
  68. end
  69.  
  70. local function onFalling()
  71.     PlayAnimation("fallAnimation")
  72. end
  73.  
  74. local function onRunning(speed)
  75.     if speed > 0.2 then
  76.         PlayAnimation("walkAnimation")
  77.     else
  78.         PlayAnimation("idleAnimation")
  79.     end
  80. end
  81.  
  82. -- Connect humanoid state events
  83. Humanoid.Seated:Connect(function()
  84.     StopAllAnimations()
  85.     PlayAnimation("sitAnimation")
  86. end)
  87.  
  88. -- no swim anim, uses running animation instead
  89. Humanoid.Swimming:Connect(onRunning)
  90.  
  91. Humanoid.Running:Connect(onRunning)
  92. Humanoid.FreeFalling:Connect(onFalling)
  93. Humanoid.Climbing:Connect(onClimbing)
  94. Humanoid.Jumping:Connect(onJumping)
  95. Humanoid.Died:Connect(function()
  96.     StopAllAnimations()
  97.     currentAnim = ""
  98. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement