Advertisement
Ubicast

Sprint Script | ROBLOX

Nov 21st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local Humanoid = script.Parent:FindFirstChild("Humanoid")
  2. local UserInputService = game:GetService("UserInputService")
  3. local Key = Enum.KeyCode.LeftShift
  4. local Camera = workspace.CurrentCamera
  5. local DefaultFOV = Camera.FieldOfView
  6. local SprintingFOV = DefaultFOV + 3
  7. local DefaultSpeed = game.StarterPlayer.CharacterWalkSpeed
  8. local SprintSpeed = DefaultSpeed * 2
  9. local TweenWaitTime = 0.15
  10. local Toggle = false
  11. local Sprinting = false
  12.  
  13. local TweenService = game:GetService("TweenService")
  14. local MyTweenInfo = TweenInfo.new(TweenWaitTime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
  15. local SprintingFOV_Properties = {FieldOfView = SprintingFOV}
  16. local DefaultFOV_Properties = {FieldOfView = DefaultFOV}
  17.  
  18. local SpintingFOV_Animation = TweenService:Create(Camera, MyTweenInfo, SprintingFOV_Properties)
  19. local DefaultFOV_Animation = TweenService:Create(Camera, MyTweenInfo, DefaultFOV_Properties)
  20.  
  21. UserInputService.InputBegan:Connect(function(Input)
  22.     if Input.KeyCode == Key then
  23.         if Toggle == false then
  24.             Sprinting = true
  25.  
  26.             while Sprinting == true do
  27.                 SpintingFOV_Animation:Play()
  28.                 Humanoid.WalkSpeed = SprintSpeed
  29.                 wait()
  30.             end
  31.         else
  32.             Sprinting = not Sprinting
  33.  
  34.             if Sprinting == true then
  35.                 SpintingFOV_Animation:Play()
  36.                 Humanoid.WalkSpeed = SprintSpeed
  37.             elseif Sprinting == false then
  38.                 DefaultFOV_Animation:Play()
  39.                 Humanoid.WalkSpeed = DefaultSpeed
  40.             end
  41.         end
  42.     end
  43. end)
  44.  
  45. UserInputService.InputEnded:Connect(function(Input)
  46.     if Input.KeyCode == Key then
  47.         if Toggle == false then
  48.             Sprinting = false
  49.  
  50.             while Sprinting == false do
  51.                 DefaultFOV_Animation:Play()
  52.                 Humanoid.WalkSpeed = DefaultSpeed
  53.                 wait()
  54.             end
  55.         end
  56.     end
  57. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement