Advertisement
HowToRoblox

SprintScript

Dec 27th, 2022
2,571
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 1 0
  1. --Speed values
  2. local sprintSpeed = 30
  3. local defaultSpeed = 16
  4.  
  5. --Camera FOV values
  6. local defaultFOV = 70
  7. local fovMultiplier = 0.1
  8.  
  9. --Streaks particles settings
  10. local windStreaksMinimumSpeed = 20
  11. local windStreaksMinimumRate = 1500
  12.  
  13. --Sprinting buttons
  14. local sprintInputs = {Enum.KeyCode.LeftControl, Enum.KeyCode.LeftShift}
  15.  
  16. --Sprint toggle enabled or not
  17. local toggle = false
  18.  
  19.  
  20. local cas = game:GetService("ContextActionService")
  21.  
  22. local camera = workspace.CurrentCamera
  23.  
  24. local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
  25. local humanoid = character:WaitForChild("Humanoid")
  26.  
  27. local windStreaks = camera:FindFirstChild(character.Name .. "'s wind streaks") or game.ReplicatedStorage:FindFirstChild(character.Name .. "'s wind streaks") or game.ReplicatedStorage:WaitForChild("SprintReplicatedStorage"):WaitForChild("StreaksPart"):Clone()
  28. windStreaks.Name = character.Name .. "'s wind streaks"
  29.  
  30.  
  31. function lerp(a, b, t)
  32.     return a + (b - a) * t
  33. end
  34.  
  35.  
  36. function sprintAction(actionName, inputState, inputObject)
  37.    
  38.     if actionName == "SPRINT" then
  39.        
  40.         if inputState == Enum.UserInputState.Begin then
  41.            
  42.             if toggle then
  43.                 humanoid.WalkSpeed = humanoid.WalkSpeed == defaultSpeed and sprintSpeed or defaultSpeed
  44.                
  45.             else
  46.                 humanoid.WalkSpeed = sprintSpeed
  47.             end
  48.            
  49.         elseif inputState == Enum.UserInputState.End then
  50.             if not toggle then
  51.                 humanoid.WalkSpeed = defaultSpeed
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. cas:BindAction("SPRINT", sprintAction, true, unpack(sprintInputs))
  58.  
  59.  
  60.  
  61. function handleWindStreaks()
  62.    
  63.     local currentFOV = camera.FieldOfView
  64.    
  65.     if (humanoid.WalkSpeed > defaultSpeed and humanoid.MoveDirection.Magnitude > 0) then
  66.        
  67.         local goalFOV = (humanoid.WalkSpeed / defaultSpeed) * defaultFOV
  68.         goalFOV = defaultFOV + ((goalFOV - defaultFOV) * fovMultiplier)
  69.        
  70.         camera.FieldOfView = lerp(currentFOV, goalFOV, 0.2)
  71.        
  72.     else
  73.         camera.FieldOfView = lerp(currentFOV, defaultFOV, 0.2)
  74.     end
  75.    
  76.     if (humanoid.WalkSpeed >= windStreaksMinimumSpeed and humanoid.MoveDirection.Magnitude > 0) then
  77.        
  78.         windStreaks.CFrame = camera.CFrame + camera.CFrame.LookVector * (13 / (camera.FieldOfView / defaultFOV))
  79.        
  80.         windStreaks.Attachment.ParticleEmitter.Rate = (humanoid.WalkSpeed / windStreaksMinimumSpeed) * windStreaksMinimumRate
  81.        
  82.         windStreaks.Parent = camera
  83.        
  84.     else
  85.         windStreaks.Parent = game.ReplicatedStorage
  86.     end
  87. end
  88.  
  89. game:GetService("RunService").RenderStepped:Connect(handleWindStreaks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement