ANIMATIONS: when CUSTOM animation STOPS - the WALK ANIM is STUCK ON - help?

Hey all - we have a custom crouch animation triggered by the CTRL key. The animation works fine, but when you hit CTRL again to toggle it off - the character stands and the walk animation is stuck on.

Why is the walk animation stuck ON after the custom animation STOPS ?

We really appreciate the help - Thx!

local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local playerGui =  player:WaitForChild("PlayerGui")
local mainGui = playerGui:WaitForChild("MainGUI")
local crawlingAnimation = "rbxassetid://14120438445" --this is for Crouch animation
local animObj = Instance.new("Animation")
animObj.AnimationId = crawlingAnimation
local loadedAnim = player.Character.Humanoid:LoadAnimation(animObj)
local animPlaying = false
local standButton = mainGui:WaitForChild("Stand")
local crouchButton = mainGui:WaitForChild("Crouch")

function crouch()

	if not player:FindFirstChild("Stuck") then --might need stuck tag for stun grenade
		if character:FindFirstChild("Shovel") then
		else
			if humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then
				if animPlaying == false then
					animPlaying = true
					if not player:FindFirstChild("Crouching") then
						local crouchTag = Instance.new("StringValue")
						crouchTag.Name = "Crouching"
						crouchTag.Parent = player
					end
					for _, playingTracks in pairs(humanoid:GetPlayingAnimationTracks()) do--added 12.28
						playingTracks:Stop()--added 12.28
					end
player.Character.Humanoid:LoadAnimation(animObj)						
						loadedAnim:Play()
						humanoid.WalkSpeed = 8
						humanoid.JumpPower = 0
						--character.HumanoidRootPart.CanCollide = false --removed 12.28
						crouchButton.Visible = false
						standButton.Visible = true
						humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)--added 12.28					
				else
					for i , v in pairs(player:GetChildren()) do
						if v.Name == "Crouching" then
							v:Destroy()
						end
					end
					animPlaying = false
					humanoid.WalkSpeed = 16
					humanoid.JumpPower = 50
					character.HumanoidRootPart.CanCollide = true
					for i , v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
						v:Stop()
					end
					crouchButton.Visible = true                      
					standButton.Visible = false
					humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)

				end--if animplaying == false
			end--if humanoid getstate ~=
		end -- shovel
	end --if not player("stuck")	
end

userInputService.InputBegan:Connect(function(input,gpe)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		print("Corect input")
		crouch()
	end
end)

Edits: code cleanup

2 Likes

What is

humanoid.WalkSpeed = 8
humanoid.JumpPower = 0

Maybe it’s a reason that it stops or maybe not*

Someone’s gotta know why the animation doesn’t stop - any help?