I have a sprinting system, and as well as a crouching system. The sprinting system works, as well as the crouching system. But what bugs me is the animation, it is messed up and I would need a little help with it. I have two animations one for Idle, one for Moving. While you are idle and press the crawl button āCā the script will work perfectly when you walk it will play the walking animation, when you are idle it will play the idle animation. But what is the bug? The bug occurs when you are walking and press the crawl button āCā then the game just plays the idle animation and it will until you stop walking, then everything will go back to normal. (These animations are just starter animations, I will make new better ones!)
Here is a video of what is happening: Video
Here is the block of code:
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local crawling = false
local defaultSpeed = 16
local crawlingSpeed = 10
local crawlKey = Enum.KeyCode.C
local animI = Instance.new("Animation")
animI.AnimationId = "rbxassetid://14166499405"
local animW = Instance.new("Animation")
animW.AnimationId = "rbxassetid://14167146354"
local animationI = animator:LoadAnimation(animI)
local animationW = animator:LoadAnimation(animW)
local uis = game:GetService("UserInputService")
local sprinting = false
uis.InputBegan:Connect(function(keyCode, _gameProcessed)
if not _gameProcessed then
if keyCode.KeyCode == crawlKey then
if not sprinting then
crawling = true
animationI:Play()
humanoid.WalkSpeed = crawlingSpeed
humanoid.Running:Connect(function(movementSpeed)
if crawling then
if movementSpeed > 0 then
if not animationW.IsPlaying then
animationI:Stop()
animationW:Play()
end
else
if animationW.IsPlaying then
animationW:Stop()
animationI:Play()
end
end
end
end)
else
crawling = false
humanoid.WalkSpeed = defaultSpeed
end
end
end
end)
The sprinting and crawling script are 2 in 1 script, that part is the crawl part. If anyone has an idea of how my bug can be fixed, please post it here. Thank you so much, have a great day!