Advertisement
HowToRoblox

DashHandler

Nov 18th, 2020 (edited)
1,838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. local uis = game:GetService("UserInputService")
  2.  
  3.  
  4. local char = script.Parent
  5.  
  6.  
  7. local dashLength = 0.05
  8.  
  9. local cooldown = 2
  10. local isCoolingDown = false
  11.  
  12.  
  13. local function handleDash(velocity)
  14.    
  15.    
  16.     if isCoolingDown then return end
  17.     isCoolingDown = true
  18.    
  19.  
  20.     local bv = Instance.new("BodyVelocity")
  21.     bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  22.     bv.Velocity = velocity
  23.  
  24.     bv.Parent = char.HumanoidRootPart
  25.    
  26.     wait(dashLength)
  27.  
  28.     bv:Destroy()
  29.    
  30.     wait(cooldown - dashLength)
  31.     isCoolingDown = false
  32. end
  33.  
  34.  
  35. uis.InputBegan:Connect(function(key, processed)
  36.    
  37.     if processed then return end
  38.    
  39.  
  40.     if key.KeyCode == Enum.KeyCode.Q then
  41.  
  42.         local velocity = -char.HumanoidRootPart.CFrame.RightVector * 100 + Vector3.new(0, 10, 0)
  43.  
  44.         handleDash(velocity)
  45.  
  46.  
  47.     elseif key.KeyCode == Enum.KeyCode.E then
  48.  
  49.         local velocity = char.HumanoidRootPart.CFrame.RightVector * 100 + Vector3.new(0, 10, 0)
  50.  
  51.         handleDash(velocity)
  52.     end
  53. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement