Death animation script not playing animation

I have a script that is supposed to play an animation where a player dies. It enables the gui in the last part of the script so i know it works. But the animation does not play. There are no errors in the output.

local hum = script.Parent.Humanoid

hum.Died:Connect(function()
	local animator = Instance.new("Animator", hum)
	local Anim = Instance.new("Animation", hum)
	Anim.AnimationId = "rbxassetid://10077836100"
	local animationTrack = animator:LoadAnimation(Anim)
	animationTrack:Play()
	game.Players.LocalPlayer.PlayerGui.DeathScreen.Frame.LocalScript.Disabled = false
end)



Does the character not break apart on death, so that wouldn’t allow for an animation to be played

I set it so that the player’s joints wont break, do I have to set it back to normal?

Ohh okay I see. The way that I have done it before is I disable Enum.HumanoidStateType.Dead, have a function keeping track of when the player’s health changes, and if it reaches 0 then the animation plays. Once the animation is done I just reload the character

1 Like

Dont load animations like that, have them as object in some folder.
also no need to create animator for humanoid.

Ok but will that fix the problem?

Who knows, until you try. If it wont, then we will try different methods

1 Like

I tried to do what you said, didn’t seem to do anything.

could you please show a code with every new attempt?

I just changed this…

	local animator = hum.Animator

let me just.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local anim = path.to.animmation

hum.Died:Connect(function()
local track = anim.Animator:LoadAnimation(anim)
track:Play()
end)

What is path.to.animation?

And do I have to make a animation instance manually for this script to work?

just write a path to your anim, as you do usually for objects. like animFolder.DeathAnim

Yes, the way you are doing its bad practice

The reason before I created the instances due to I got an error that read:

LoadAnimation requires an Animation object

But here is the edited script:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local anim = char.DeathAnim

hum.Died:Connect(function()
	local track = hum.Animator:LoadAnimation(anim)
	track:Play()
	game.Players.LocalPlayer.PlayerGui.DeathScreen.Frame.LocalScript.Disabled = false
end)