What do you want to achieve?
A Sprinting script that does not mess up the animation.
What is the issue?
Whenever my character stops sprinting the animation does not go back to the walking animation, instead, it seems to combine both the run and walk animation. I am using the default animations for a walk and run from Roblox if that matters. See Gifs below:
Default walk animation: https://gyazo.com/ed7a86b3ac94aa7e56e4eaf4dda21359
Weird Combo animation: https://gyazo.com/40676dab30638ccdff6a3c4b576930af
This is my sprint script (double tap w to sprint):
UIS.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.W then
print("should be running")
local now = tick()
local difference = (now - lastTime)
if difference <= 0.2 then
run = true
hum.WalkSpeed = 18
end
lastTime = tick()
end
end)
UIS.InputEnded:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.W and run == true then
run = false
hum.WalkSpeed = 10
end
end)
UIS.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.W then
print("should be running")
local now = tick()
local difference = (now - lastTime)
if difference <= 0.2 then
run = true
end
lastTime = tick()
end
end)
UIS.InputEnded:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode.W and run == true then
run = false
end
end)
hum.Running:connect(function(speed)
if run then
hum.WalkSpeed = 18
else
hum.WalkSpeed = 10
end)
For some debugging steps, does this issue still occur if you come to a complete stop and then resume walking or does it return to the default walking animation?
Sorry for the late replies. I think you are right. The two animation, runanim and walkanim seem to be blending together. To solve this I think the best way to to disable the runanim when walking and vice versa.