Animation will not stop playing?

Hi.

So, I have a script that plays an animation when a player is dead. When the player is revived to full health, I want that player to stop its animation.

I programmed something like this, but the animation wont stop playing.

Here is the program. :

local Character = script.Parent
local Humanoid = Character.Humanoid
local Animation = Humanoid.Animator:LoadAnimation(script.Animation)

Humanoid.HealthChanged:Connect(function(Health)

	if Health == 0 and not Animation.IsPlaying then

		Animation:Play()
		Animation:AdjustWeight(3)
		script.Parent.HumanoidRootPart.Anchored = true
	end
end)

Humanoid.HealthChanged:Connect(function(Health)
	if Health > 99 and Animation.IsPlaying and script.Parent.HumanoidRootPart.Anchored == true then
		script.Parent.HumanoidRootPart.Anchored = false
		
		Animation:Stop()

	end
end)

Here is a video example of what im talking about:
robloxapp-20221003-1424431.wmv (3.3 MB)

Help would be appreciated? Thank you.

well, in the video, the animation doesn’t stop

also, you can’t do anything to a player once their HumanoidState is set to dead.

Try printing Health to see what the value is. If it never gets to >99 then the script that adds Health is your issue.

You should use humanoid.Died instead of an if statement.