Advertisement
oopsrainbow4

Shift to Sprint

May 3rd, 2023
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. -- Put LocalScript in StarterPlayerScripts
  2.  
  3. local Player = game:GetService("Players").LocalPlayer
  4. local Humanoid = nil
  5.  
  6. local UserInputService = game:GetService("UserInputService")
  7.  
  8. local isRunning = false
  9. local triggerKey = Enum.KeyCode.LeftShift
  10.  
  11. local REGULAR_SPEED = 16
  12. local RUN_SPEED = 30
  13.  
  14.  
  15. local function connectToHumanoid(character)
  16.     Humanoid = character:WaitForChild("Humanoid")
  17.  
  18.     UserInputService.InputBegan:Connect(function(input)
  19.         if input and input.KeyCode == triggerKey then
  20.             Humanoid.WalkSpeed = RUN_SPEED
  21.             isRunning = true
  22.         end
  23.     end)
  24.  
  25.     UserInputService.InputEnded:Connect(function(input)
  26.         if input and input.KeyCode == triggerKey then
  27.             Humanoid.WalkSpeed = REGULAR_SPEED
  28.             isRunning = false
  29.         end
  30.     end)
  31. end
  32.  
  33.  
  34. connectToHumanoid(Player.Character or Player.CharacterAdded:Wait())
  35.  
  36.  
  37. Player.CharacterAdded:Connect(function(character)
  38.     if Humanoid then
  39.         Humanoid:Destroy()
  40.     end
  41.  
  42.     connectToHumanoid(character)
  43. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement