I have a small problem, that is actually really hard for me to solve. My question is “How can I detect if player is still holding a button?” Let’s get into the details.
local SpeedValue_1 = 25 local SpeedValue_2 = 10 local SpeedValue_3 = 0 Character.Humanoid.Running:Connect(function(SpeedValue_4) SpeedValue_3 = SpeedValue_4 print(SpeedValue_3) end) game:GetService('ContextActionService'):BindAction("ShiftSprint", function(actionName, inputState, inputObj) if inputState == Enum.UserInputState.Begin and SpeedValue_3 > 1 then Running = true Character.Humanoid.WalkSpeed = SpeedValue_1 CamOut:Play() CamIn:Pause() RunAnimation:Play() elseif inputState == Enum.UserInputState.Begin and SpeedValue_3 < 3 then Running = false Character.Humanoid.WalkSpeed = SpeedValue_2 CamIn:Play() CamOut:Pause() RunAnimation:Stop() elseif inputState == Enum.UserInputState.End then Running = false Character.Humanoid.WalkSpeed = SpeedValue_2 CamIn:Play() CamOut:Pause() RunAnimation:Stop() JumpAnimation:Stop() ClimbAnimation:Stop() SwimAnimation:Stop() FallAnimation:Stop() end end, false, Enum.KeyCode.LeftShift)
Here is the problem:
When player starts walking and then starts holding LeftShift, he will start playing run animation, but if player stops walking or running(WASD) and holds LeftShift, run animation will still play, which I don’t want to happen. When player’s current speed is 0 or player is in idle form, but he is still holding a button for running, he won’t play run animation. So, I need some sort of help, to detect or track player’s speed in the function for Input. I don’t want to use loops for tracking, because loops grow lag in the game.
I tried placing the function that tracks player’s speed in the function for Input. Though, once I release the shift button and start walking, my player won’t walk, he will run (play run animation).
Is there any possible way how am I going to track player’s speed? If you think there is, please reply!