Advertisement
Janelijs

Script

Jul 8th, 2023
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local Humanoid = script.Parent:WaitForChild("Humanoid")
  2. local shiftKeyDown = false
  3. local defaultWalkSpeed = Humanoid.WalkSpeed
  4. local sprintSpeed = 32 -- Adjust this value to set the sprint speed
  5.  
  6. -- Function to handle when the shift key is pressed down
  7. local function onShiftDown()
  8.     shiftKeyDown = true
  9.     if Humanoid and Humanoid.WalkSpeed > 0 then
  10.         Humanoid.WalkSpeed = sprintSpeed
  11.     end
  12. end
  13.  
  14. -- Function to handle when the shift key is released
  15. local function onShiftUp()
  16.     shiftKeyDown = false
  17.     if Humanoid and Humanoid.WalkSpeed > 0 then
  18.         Humanoid.WalkSpeed = defaultWalkSpeed
  19.     end
  20. end
  21.  
  22. -- Function to handle when the humanoid's WalkSpeed changes
  23. local function onWalkSpeedChange()
  24.     if shiftKeyDown and Humanoid and Humanoid.WalkSpeed > 0 then
  25.         Humanoid.WalkSpeed = sprintSpeed
  26.     end
  27. end
  28.  
  29. -- Bind the shift key events
  30. game:GetService("UserInputService").InputBegan:Connect(function(input)
  31.     if input.KeyCode == Enum.KeyCode.LeftShift then
  32.         onShiftDown()
  33.     end
  34. end)
  35.  
  36. game:GetService("UserInputService").InputEnded:Connect(function(input)
  37.     if input.KeyCode == Enum.KeyCode.LeftShift then
  38.         onShiftUp()
  39.     end
  40. end)
  41.  
  42. -- Bind the WalkSpeed change event
  43. Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(onWalkSpeedChange)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement