lV0rd

Sprint

Mar 14th, 2024
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. local module = {}
  2.  
  3. local uis = game:GetService("UserInputService")
  4. local twnService = game:GetService("TweenService")
  5. local runService = game:GetService("RunService")
  6. local setting = require(script.Parent.Important.Settings)
  7.  
  8. local twnInfo = TweenInfo.new(.1)
  9.  
  10. local plr = game.Players.LocalPlayer
  11. local cam = workspace.CurrentCamera
  12.  
  13. local animation = script.Animation
  14. animation.AnimationId = setting.Sprint.SprintAnim
  15.  
  16. local char : Model
  17. local hum : Humanoid
  18. local anim : Animator
  19. local spra
  20.  
  21. local isSprint = false
  22. local runCon
  23.  
  24. module.Init = function()
  25.    
  26.     char = plr.Character or plr.CharacterAdded:Wait()
  27.     hum = char.Humanoid
  28.     anim = hum.Animator
  29.     spra = anim:LoadAnimation(animation)
  30.    
  31.     plr.CharacterAdded:Connect(function(c) char = c hum = c.Humanoid anim = c.Humanoid.Animator spra = c.Humanoid.Animator:LoadAnimation(animation) end)
  32.    
  33.     uis.InputBegan:Connect(function(i, g)
  34.         if g then return end
  35.         if i.KeyCode == setting.Sprint.SprintKey then
  36.             isSprint = true
  37.             hum.WalkSpeed += setting.Sprint.SprintAmount
  38.             twnService:Create(cam, twnInfo, {FieldOfView = cam.FieldOfView + setting.Sprint.SprintFOV}):Play()
  39.             spra:Play()
  40.            
  41.             runCon = runService.Heartbeat:Connect(function()
  42.                 if hum.MoveDirection.Magnitude > 0 then
  43.                     if isSprint then
  44.                         if not spra.IsPlaying then
  45.                             spra:Play()
  46.                         end
  47.                     end
  48.                 else
  49.                     if isSprint then
  50.                         if spra.IsPlaying then
  51.                             spra:Stop()
  52.                         end
  53.                     end
  54.                 end
  55.             end)
  56.         end
  57.     end)
  58.    
  59.     uis.InputEnded:Connect(function(i, g)
  60.         if g then return end
  61.         if i.KeyCode == setting.Sprint.SprintKey then
  62.             isSprint = false
  63.             hum.WalkSpeed -= setting.Sprint.SprintAmount
  64.             twnService:Create(cam, twnInfo, {FieldOfView = cam.FieldOfView - setting.Sprint.SprintFOV}):Play()
  65.             spra:Stop()
  66.             runCon:Disconnect()
  67.             runCon = nil
  68.         end
  69.     end)
  70.    
  71.    
  72.    
  73. end
  74.  
  75. return module
  76.  
Advertisement
Add Comment
Please, Sign In to add comment