local UserInputService = game:GetService("UserInputService") local player = game:GetService("Players").LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local sprinting = false local lastTick = tick() local oldWS = nil -- It doesn't work if I set the walkspeed here. Can this be explained as well? UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == Enum.KeyCode.W then local difference = tick() - lastTick if difference <= 0.8 then sprinting = true oldWS = character.Humanoid.WalkSpeed character.Humanoid.WalkSpeed = oldWS * 1.8 print("Sprinting!") end lastTick = tick() end end) UserInputService.InputEnded:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == Enum.KeyCode.W and sprinting then sprinting = false character.Humanoid.WalkSpeed = oldWS print("Sprinting ended!") end end)
I really don’t like using scripts I don’t understand. So an explanation of why the tick() works would be great.
I mainly want to know why the tick() part works, and that’s pretty much it. A full step-by-step explanation wouldn’t be that bad as well.