shiftDown = false momentum = 0 x = game:GetService("UserInputService") x.InputBegan:connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift then shiftDown = true print("test") newThread2 = coroutine.create(function() repeat if momentum == 0 then momentum = 1 end if momentum == 1 then humanoid.WalkSpeed = 20 momentum = 2 elseif momentum == 2 then humanoid.WalkSpeed = 32 end wait(3) until shiftDown == false end) coroutine.resume(newThread2) end end) x.InputEnded:connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift then shiftDown = false wait() humanoid.WalkSpeed = 10 momentum = 0 print("Player stopped running from momentum "..momentum) end end)
This script works fine, mostly. When you hold down shift for the first time, your walkspeed goes from 10 to 20. After 3 seconds, it goes from 20 to 32. This is as expected. Now, when you release shift and hold it down again, your walkspeed goes from 10 to 20 as expected... and then instead of waiting 3 seconds, it seems to wait a random amount of time before boostin your WalkSpeed to 32. I believe this is to do with how coroutines work, but I'm not entirely sure how they do.
"Note: ROBLOX also provides a function to create threads that may be used in replace of coroutines if creating a new thread is the only
goal. "
Seems to be your case ^_^
Use print on the wait(s), to know the time elapsed.