Advertisement
Mdbook

Untitled

Mar 6th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.97 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3. local UserInputService = game:GetService("UserInputService")
  4. local Player = Players.LocalPlayer
  5. local Mouse = Player:GetMouse()
  6. local Camera = workspace.CurrentCamera
  7. local Character = Player.Character
  8. local Humanoid = Character.Humanoid
  9. local Head = Character.Head
  10. local Torso = Character.Torso
  11. local RootPart = Character.HumanoidRootPart
  12. local RightArm = Character["Right Arm"]
  13. local LeftArm = Character["Left Arm"]
  14. local RightLeg = Character["Right Leg"]
  15. local LeftLeg = Character["Left Leg"]
  16. local Functions = {}
  17. local KeyHolds = {}
  18. local Data, ReplicatedData = {}, {Animation = "Idle", JumpEnabled = true}
  19. setmetatable(Data, {
  20. __metatable = {},
  21. __index = function(Self, Index)
  22. return ReplicatedData[Index]
  23. end,
  24. __newindex = function(Self, Index, Value)
  25. if Data.Changed and type(Data.Changed) == "function" then
  26. Data.Changed(Index, Value)
  27. end
  28. ReplicatedData[Index] = Value
  29. end
  30. })
  31. function Functions.Weld(P0, P1, C0, C1)
  32. local Weld = Instance.new("Weld", P0)
  33. Weld.Part0, Weld.Part1, Weld.C0, Weld.C1 = P0, P1, C0, C1
  34. return Weld
  35. end
  36. local RootWeld = Functions.Weld(RootPart, Torso, CFrame.new(), CFrame.new())
  37. local RAWeld = Functions.Weld(Torso, RightArm, CFrame.new(1.5, 0.5, 0), CFrame.new(0, 0.5, 0))
  38. local LAWeld = Functions.Weld(Torso, LeftArm, CFrame.new(-1.5, 0.5, 0), CFrame.new(0, 0.5, 0))
  39. local RLWeld = Functions.Weld(Torso, RightLeg, CFrame.new(0.5, -1.5, 0), CFrame.new(0, 0.5, 0))
  40. local LLWeld = Functions.Weld(Torso, LeftLeg, CFrame.new(-0.5, -1.5, 0), CFrame.new(0, 0.5, 0))
  41. function Data.Changed(Index, Value)
  42. if Index == "Animation" then
  43. if Value == "Running" then
  44. Humanoid.WalkSpeed = 20
  45. else
  46. Humanoid.WalkSpeed = 12
  47. end
  48. end
  49. end
  50. Mouse.KeyDown:connect(function(K)
  51. local Key = K:lower()
  52. if Key:byte() == 48 then
  53. KeyHolds.SHIFT = true
  54. end
  55. end)
  56. Mouse.KeyUp:connect(function(K)
  57. local Key = K:lower()
  58. if Key:byte() == 48 then
  59. KeyHolds.SHIFT = false
  60. end
  61. end)
  62. Humanoid.Running:connect(function(Speed)
  63. if Speed > 0 then
  64. if KeyHolds.SHIFT then
  65. Data.Animation = "Running"
  66. elseif Data.Animation == "Idle" then
  67. Data.Animation = "Walking"
  68. end
  69. elseif Data.Animation == "Walking" or Data.Animation == "Running" then
  70. Data.Animation = "Idle"
  71. end
  72. end)
  73. Humanoid.Jumping:connect(function(Active)
  74. if Data.JumpEnabled then
  75. Data.JumpEnabled = false
  76. Humanoid.JumpPower = 40
  77. if Data.Animation == "Running" then
  78. Functions.Flip()
  79. elseif Active then
  80. Data.Animation = "Jumping"
  81. else
  82. Data.Animation = "Idle"
  83. end
  84. wait(0.25)
  85. Humanoid.JumpPower = 0
  86. wait(1)
  87. Humanoid.JumpPower = 40
  88. Data.JumpEnabled = true
  89. end
  90. end)
  91. Humanoid.FreeFalling:connect(function(Active)
  92. if Active then
  93. Data.Animation = "Falling"
  94. else
  95. Data.Animation = "Idle"
  96. end
  97. end)
  98. Humanoid.WalkSpeed, Humanoid.JumpPower = 12, 40
  99. function Functions.Animate(Angle)
  100. if Data.Animation == "Idle" then
  101. RootWeld.C0 = RootWeld.C0:Lerp(CFrame.new() * CFrame.Angles(math.sin(Angle / 2) * math.pi / 256, math.sin(Angle) * math.pi / 128, 0), 0.2)
  102. RAWeld.C0 = RAWeld.C0:Lerp(CFrame.new(1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle) * math.pi / 32, 0, math.pi / 96), 0.2)
  103. LAWeld.C0 = LAWeld.C0:Lerp(CFrame.new(-1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle) * -math.pi / 32, 0, -math.pi / 96), 0.2)
  104. RLWeld.C0 = RLWeld.C0:Lerp(CFrame.new(0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle) * -math.pi / 48, 0, math.pi / 128), 0.2)
  105. LLWeld.C0 = LLWeld.C0:Lerp(CFrame.new(-0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle) * math.pi / 48, 0, -math.pi / 128), 0.2)
  106. elseif Data.Animation == "Walking" then
  107. RootWeld.C0 = RootWeld.C0:Lerp(CFrame.new() * CFrame.Angles((math.sin(Angle * 2) - 1) * math.pi / 128, math.sin(Angle * 4) * math.pi / 48, 0), 0.2)
  108. RAWeld.C0 = RAWeld.C0:Lerp(CFrame.new(1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 4) * math.pi / 10, 0, math.pi / 64), 0.2)
  109. LAWeld.C0 = LAWeld.C0:Lerp(CFrame.new(-1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 4) * -math.pi / 10, 0, -math.pi / 64), 0.2)
  110. RLWeld.C0 = RLWeld.C0:Lerp(CFrame.new(0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 4) * -math.pi / 12, 0, math.pi / 72), 0.2)
  111. LLWeld.C0 = LLWeld.C0:Lerp(CFrame.new(-0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 4) * math.pi / 12, 0, -math.pi / 72), 0.2)
  112. elseif Data.Animation == "Running" then
  113. RootWeld.C0 = RootWeld.C0:Lerp(CFrame.new() * CFrame.Angles((math.sin(Angle * 2) - 1) * math.pi / 64, math.sin(Angle * 8) * math.pi / 32, 0), 0.2)
  114. RAWeld.C0 = RAWeld.C0:Lerp(CFrame.new(1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 6) * math.pi / 6, 0, math.pi / 24), 0.2)
  115. LAWeld.C0 = LAWeld.C0:Lerp(CFrame.new(-1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 6) * -math.pi / 6, 0, -math.pi / 24), 0.2)
  116. RLWeld.C0 = RLWeld.C0:Lerp(CFrame.new(0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 6) * -math.pi / 8, 0, math.pi / 32), 0.2)
  117. LLWeld.C0 = LLWeld.C0:Lerp(CFrame.new(-0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 6) * math.pi / 8, 0, -math.pi / 32), 0.2)
  118. elseif Data.Animation == "Jumping" then
  119. RootWeld.C0 = RootWeld.C0:Lerp(CFrame.new() * CFrame.Angles((math.sin(Angle * 4) + 2) * math.pi / 64, math.sin(Angle * 8) * math.pi / 64, 0), 0.2)
  120. RAWeld.C0 = RAWeld.C0:Lerp(CFrame.new(1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 4) * math.pi / 16, 0, math.pi / 2 - (math.sin(Angle * 2) + 4) * math.pi / 12), 0.2)
  121. LAWeld.C0 = LAWeld.C0:Lerp(CFrame.new(-1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 4) * -math.pi / 16, 0, -math.pi / 2 + (math.sin(Angle * 2) + 4) * math.pi / 12), 0.2)
  122. RLWeld.C0 = RLWeld.C0:Lerp(CFrame.new(0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 4) * -math.pi / 24, 0, math.pi / 64), 0.2)
  123. LLWeld.C0 = LLWeld.C0:Lerp(CFrame.new(-0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 4) * math.pi / 24, 0, -math.pi / 64), 0.2)
  124. elseif Data.Animation == "Falling" then
  125. RootWeld.C0 = RootWeld.C0:Lerp(CFrame.new() * CFrame.Angles((math.sin(Angle * 2) + 2) * math.pi / 64, math.sin(Angle * 4) * math.pi / 64, 0), 0.2)
  126. RAWeld.C0 = RAWeld.C0:Lerp(CFrame.new(1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 4) * math.pi / 16, 0, math.pi / 4 - (math.sin(Angle * 2) + 2) * math.pi / 16), 0.2)
  127. LAWeld.C0 = LAWeld.C0:Lerp(CFrame.new(-1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle * 4) * -math.pi / 16, 0, -math.pi / 4 + (math.sin(Angle * 2) + 2) * math.pi / 16), 0.2)
  128. RLWeld.C0 = RLWeld.C0:Lerp(CFrame.new(0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 4) * -math.pi / 24, 0, math.pi / 32), 0.2)
  129. LLWeld.C0 = LLWeld.C0:Lerp(CFrame.new(-0.5, -1.5, 0) * CFrame.Angles(math.sin(Angle * 4) * math.pi / 24, 0, -math.pi / 32), 0.2)
  130. end
  131. end
  132. function Functions.Flip()
  133. Data.Animation = "Flipping"
  134. local Count = 0
  135. coroutine.wrap(function()
  136. RunService.Heartbeat:connect(function()
  137. if Count then
  138. if Count < 2 then
  139. Count = Count + 0.05
  140. local Angle = Count * math.pi / 4
  141. RootWeld.C0 = RootWeld.C0:Lerp(CFrame.new(0, math.sin(Angle * 2) ^ 2 * 4, 0) * CFrame.Angles(math.sin(Angle) * -math.pi * 2, math.sin(Angle) * math.pi / 24, 0), 0.6)
  142. RAWeld.C0 = RAWeld.C0:Lerp(CFrame.new(1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle) * math.pi / 64, 0, math.pi / 2 - math.pi / 5), 0.6)
  143. LAWeld.C0 = LAWeld.C0:Lerp(CFrame.new(-1.5, 0.5, 0) * CFrame.Angles(math.sin(Angle) * -math.pi / 64, 0, -math.pi / 2 + math.pi / 5), 0.6)
  144. RLWeld.C0 = RLWeld.C0:Lerp(CFrame.new(0.5, -1.3, 0) * CFrame.Angles(math.pi / 3, 0, math.pi / 64), 0.6)
  145. LLWeld.C0 = LLWeld.C0:Lerp(CFrame.new(-0.5, -1.3, 0) * CFrame.Angles(math.pi / 3, 0, -math.pi / 64), 0.6)
  146. else
  147. Count = nil
  148. Data.Animation = "Running"
  149. end
  150. else
  151. coroutine.yield()
  152. end
  153. end)
  154. end)()
  155. end
  156. local Angle = 0
  157. RunService.Heartbeat:connect(function()
  158. Angle = Angle + math.pi / 128
  159. Functions.Animate(Angle)
  160. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement