Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Humanoid = script.Parent:WaitForChild("Humanoid")
- local shiftKeyDown = false
- local defaultWalkSpeed = Humanoid.WalkSpeed
- local sprintSpeed = 32 -- Adjust this value to set the sprint speed
- -- Function to handle when the shift key is pressed down
- local function onShiftDown()
- shiftKeyDown = true
- if Humanoid and Humanoid.WalkSpeed > 0 then
- Humanoid.WalkSpeed = sprintSpeed
- end
- end
- -- Function to handle when the shift key is released
- local function onShiftUp()
- shiftKeyDown = false
- if Humanoid and Humanoid.WalkSpeed > 0 then
- Humanoid.WalkSpeed = defaultWalkSpeed
- end
- end
- -- Function to handle when the humanoid's WalkSpeed changes
- local function onWalkSpeedChange()
- if shiftKeyDown and Humanoid and Humanoid.WalkSpeed > 0 then
- Humanoid.WalkSpeed = sprintSpeed
- end
- end
- -- Bind the shift key events
- game:GetService("UserInputService").InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.LeftShift then
- onShiftDown()
- end
- end)
- game:GetService("UserInputService").InputEnded:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.LeftShift then
- onShiftUp()
- end
- end)
- -- Bind the WalkSpeed change event
- Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(onWalkSpeedChange)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement