Death animation not working

I am trying to make a Death animation in roblox so when someone resets or dies they will have this animation. I have a local script in the starter character scripts and this is what I have in the script

wait()

local Humanoid = script.Parent.Humanoid

Humanoid.BreakJointsOnDeath = false

local DA = Instance.new(“Animation”)

DA.AnimationnID = “rbxassetid://6162432703”

local DeathAnimation = Humanoid:LoadAnimation(DA)

Humanoid.HealthChanged:Connect(function(Health)

if Health <= 0 then

print("Died")

script.Parent.HumanoidRootPart.Anchored = true

DeathAnimation:Play()

end

end)

I am not seeing any problems with the script but I am not sure if I have missed something. I have looked on youtube to see how I could fix this problem.

1 Like

Not sure if this is like it in your real script, but you have a typo on this line:

DA.AnimationnID = "rbxassetid://6162432703"

Animationn should be Animation.

1 Like

Yes I fixed that problem but I have it in the StarterCharacterScripts is it ok in there because its not doing the animation I made. All it does is making the person just stand there frozen.
EDIT:
Does it need to be in StarterCharacterScripts or in StarterPlayerScripts?

1 Like

It’s probably best to handle this in ServerScriptService, here’s how you could do it:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player) -- function is called when a player is added

player.CharacterAdded:Connect(function(character) -- function is called when the player's has spawned

local humanoid = character:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
humanoid.Died:Connect(function() -- function called when the player dies

local anim = Instance.new("Animation", character)
anim.AnimationId = "rbxassetid://6162432703"

character.PrimaryPart.Anchored = true -- Anchor HumanoidRootPart
local track = humanoid:LoadAnimation(anim)
track:Play()

end)
end)

end)
2 Likes

Thank you for the help. It worked.