Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. --Variables--
  2. local UIS = game:GetService("UserInputService")
  3. local CAS = game:GetService("ContextActionService")
  4. local SP = game:GetService("StarterPlayer")
  5. local plr = game.Players.LocalPlayer
  6. local Freeze = "freezeMovement"
  7.  
  8.  
  9. local Character
  10. local Humanoid
  11.  
  12. --Debounces--
  13. local Roll_Delay = 3
  14. local RollReady = true
  15. local SprintEnabled = script.Parent:WaitForChild("Sprint"):WaitForChild("SprintEnabled")
  16.  
  17. --Anims--
  18. local Anims = {"rbxassetid://3500677723", --[["rbxassetid://2827609895"]]}
  19.  
  20. --Functions--
  21. local function Roll(Key, IsTyping)
  22.  
  23. --Character Checks
  24. if not Character or not Humanoid or not Character:IsDescendantOf(game.Workspace) or Humanoid:GetState() == Enum.HumanoidStateType.Dead then
  25. return
  26. else
  27. if RollReady == true and not IsTyping and Key.KeyCode == Enum.KeyCode.R and SprintEnabled.Value == false and Humanoid.Jump == false and Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
  28. RollReady = false
  29.  
  30. --Make and Choose animation
  31. local RollAnimation = Instance.new("Animation", Character)
  32. local AnimChoice = math.random(1, #Anims)
  33. RollAnimation.AnimationId = Anims[AnimChoice]
  34. RollAnimation.Name = "Roll Animation"
  35.  
  36.  
  37. --Save Original JP & WS
  38. local OriginalJP = Humanoid.JumpPower
  39. local OriginalWS = Humanoid.WalkSpeed
  40.  
  41.  
  42. --Find Target Position
  43. local TargetRoll = Character.HumanoidRootPart.Position + Character.HumanoidRootPart.CFrame.LookVector * 20
  44.  
  45.  
  46. --Load Animation and check if it loaded
  47. local LoadedAnimation
  48. local success, malfunction = pcall(function()
  49. LoadedAnimation = Humanoid:LoadAnimation(RollAnimation)
  50. end)
  51.  
  52.  
  53. --Check if Animation Loaded then proceed w/ the roll action
  54. if success then
  55.  
  56. --Change WS & JP
  57. Humanoid.JumpPower = 0
  58. Humanoid.WalkSpeed = 30
  59.  
  60. --Play Animation
  61. LoadedAnimation.Priority = Enum.AnimationPriority.Movement
  62. LoadedAnimation:Play()
  63.  
  64. --Disable User Inputs using BuildThomas method
  65. CAS:UnbindAction(
  66. Freeze,
  67. function() return Enum.ContextActionResult.Sink end,
  68. false,
  69. unpack(Enum.PlayerActions:GetEnumItems())
  70. )
  71.  
  72. Character:FindFirstChild("HumanoidRootPart").Size = Character:FindFirstChild("HumanoidRootPart").Size + Vector3.new(0, -1.25, 0)
  73. Character.Head.CanCollide = false
  74. Character.UpperTorso.CanCollide = false
  75. --Move Humanoid Until Animation Finishes
  76. repeat
  77. Humanoid:MoveTo(TargetRoll)
  78. wait()
  79. until LoadedAnimation.IsPlaying == false
  80.  
  81. --Reset WS & JP, whilst destroying the animation
  82. Character:FindFirstChild("HumanoidRootPart").Size = Character:FindFirstChild("HumanoidRootPart").Size + Vector3.new(0, 1.25, 0)
  83. Character.Head.CanCollide = true
  84. Character.UpperTorso.CanCollide = true
  85. Humanoid.WalkSpeed = OriginalWS
  86. Humanoid.JumpPower = OriginalJP
  87. RollAnimation:Destroy()
  88.  
  89. --Enable User Inputs using BuildThomas method
  90. CAS:UnbindAction(Freeze)
  91.  
  92. --Wait Roll Delay
  93. wait(Roll_Delay)
  94. RollReady = true
  95. else
  96. --Warn the server, wait roll delay and make it ready again
  97. warn("Animation Issue: "..malfunction.." Try Again In a few seconds")
  98. wait(Roll_Delay)
  99. RollReady = true
  100. end
  101. end
  102. end
  103. end
  104.  
  105.  
  106.  
  107. --Misc--
  108. local function CharacterAdded(NewCharacter)
  109. if NewCharacter and NewCharacter:WaitForChild("Humanoid") and NewCharacter.Humanoid.Health > 0 then
  110. wait(1)
  111. Character = NewCharacter
  112. Humanoid = Character.Humanoid
  113. end
  114. end
  115.  
  116. if plr:FindFirstChild("Character") then
  117. local Feedback = CharacterAdded(plr.Character)
  118. if not Feedback then
  119. warn("No Humanoid Found!")
  120. end
  121. end
  122.  
  123. local Feedback = plr.CharacterAdded:connect(CharacterAdded)
  124. if not Feedback then
  125. warn("CharacterAdded EVENT failed...")
  126. end
  127.  
  128. --Events--
  129. UIS.InputBegan:Connect(Roll)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement