Hello, I’ve recently been working on a crouching system and I’ve ran into a few issues. I managed to find a way around a few of them, but I got a few other bugs. I can’t seem to fix them, even though they seem rather simple. The bugs include:
The crouch working fine at first, but the walking animation getting bugged toggling it without me pressing LeftCTRL after I move, interrupting the idle crouch animation.
Pushing the key to stop the animation, only for the crouch walk animation to toggle itself right after I move etc.
I’ll include a short gif of this. At first from 0 - 0:02, I’m manually toggling the crouch. But after that, it toggles itself.
My Code
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 8.3
CrouchAnimationTrack:Play()
Humanoid.Running:Connect(function(speed)
if input.KeyCode == Enum.KeyCode.LeftControl and speed < 10 then
CrouchWalkAnimationTrack:Play()
end
end)
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 10.5
CrouchAnimationTrack:Stop()
CrouchWalkAnimationTrack:Stop()
end
end)
Hope that you can help me solve this as I’ve been trying to fix this for about an hour already, thanks!
I believe the issue is that it plays when the speed is less than 10. If you make it speed <10 and speed > 0.5 then it will only play when you are moving
lmk if that fixes the issue
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 8.3
CrouchAnimationTrack:Play()
Humanoid.Running:Connect(function(speed)
if input.KeyCode == Enum.KeyCode.LeftControl and speed < 10 and speed > 0.5 then
CrouchWalkAnimationTrack:Play()
end
end)
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 10.5
CrouchAnimationTrack:Stop()
CrouchWalkAnimationTrack:Stop()
end
end)
Alright, makes sense, though now I’m left with the Walk playing after I stop moving and not being able to move while holding CTRL, I’ll show a gif of this in a second.
I believe that is cause due to the fact that you do not stop the animation from playing if you aren’t moving. I think this will fix that:
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 8.3
CrouchAnimationTrack:Play()
Humanoid.Running:Connect(function(speed)
if input.KeyCode == Enum.KeyCode.LeftControl and speed < 10 and speed > 0.5 then
CrouchWalkAnimationTrack:Play()
else
CrouchWalkAnimationTrack:Stop()
end
end)
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 10.5
CrouchAnimationTrack:Stop()
CrouchWalkAnimationTrack:Stop()
end
end)
Awesome, that’s fixed too! The only thing that’s left is the movement. Whenever I crouch, I can’t seem to move in any direction without having to toggle the crouch off.
Edit
This may happen because of the studio shortcuts, one key actually worked. Testing it in game right now.
Alright, turns out that the problem with the movement was the Studio shortcuts. Thanks for helping me out, have an amazing rest of your day/night!
Final result
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 8.3
CrouchAnimationTrack:Play()
Humanoid.Running:Connect(function(speed)
if input.KeyCode == Enum.KeyCode.LeftControl and speed < 10 and speed > 0.5 then
CrouchWalkAnimationTrack:Play()
else
CrouchWalkAnimationTrack:Stop()
end
end)
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl then
Humanoid.WalkSpeed = 10.5
CrouchAnimationTrack:Stop()
CrouchWalkAnimationTrack:Stop()
end
end)