okay so im having an issue with stopping an animation after the player has stopped moving. This is for a crouching system in my game the problem is once the player has crouched then moved the crouch-walking animation doesnt stop, but when you let go of the crouch key it’s fine.
here is the code
local uis = game:GetService("UserInputService")
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script:WaitForChild("crouched"))
local anim2 = hum:LoadAnimation(script:WaitForChild("crouchedWalk"))
local crouching = false
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
hum.HipHeight = 2
hum.WalkSpeed = 8
hum.JumpPower = 0
anim.Looped = true
anim:Play()
hum.Running:Connect(function(speed)
if speed > 0 then
anim2:Play()
elseif
speed < 0 then
anim2:Stop()
end
end)
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
crouching = false
hum.HipHeight = 2
hum.WalkSpeed = 16
hum.JumpPower = 50
anim:Stop()
anim2:Stop()
end
end)
this is located inside of a local script in the StarterCharacterScripts folder