As the title suggests, I'm trying to find a way to change an animation while its playing

I am making a 2d fighting game, which includes crouching and blocking. Since there are seperate animations for blocking while crouching and standing, I want to find a way to smoothly transition between the two whether I press the crouch key or let go of it.

current code:

--you'd want to look around here////////////////////////
function animationManager(player, char)
	unCrouchEvent.OnServerEvent:Connect(function(player)
		if player == localPlayer then
			return animator:LoadAnimation(groundAnim)
		end
	end)
	crouchEvent.OnServerEvent:Connect(function(player)
		if player == localPlayer then
			return animator:LoadAnimation(crouchAnim)
		end
	end)
	if char.Crouching.Value then
		return animator:LoadAnimation(crouchAnim)
	else
		if char.HumanoidRootPart.Velocity.y>0.5 and char.HumanoidRootPart.Velocity.y<-0.5 then
			return animator:LoadAnimation(airAnim)
		else
			return animator:LoadAnimation(groundAnim)
		end
	end
end
--///////////////////////////////////



blockEvent.OnServerEvent:Connect(function (player, char)
	if player == localPlayer then
		if not player.Character.PlayerHasHurt.Value then
			local playAnim = animationManager(player, char) --calls the function
			playAnim:Play()
			
			unBlockEvent.OnServerEvent:Connect(function(player)
				if player == localPlayer then
					playAnim:Stop()
					player.Character.Blocking.Value=false
					if not char.Crouching.Value then
						player.Character.Humanoid.WalkSpeed = char.DefaultSpeed.Value
						player.Character.Humanoid.JumpPower = char.DefaultJump.Value
					end
				end
			end)
		end
	end
end)

1 comment

0

I think you will have to create an animation for crouching, one for standing up, and one for transitioning. I think you can play an animation backwards from what I remember so you can use the transition animation to go from standing to crounching and crouching to standing.