Again about death animation. Animation not working

I have this script in serverscript folder

local animations = {
	"13123760883", "13123772558", "13123778553", "13123786180"
}

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 die		
			local anim = Instance.new("Animation", character)
			anim.AnimationId = "rbxassetid://"..animations[math.random(1, 4)]
			character.PrimaryPart.Anchored = true
--This is another variant, when animation is a child of this script. Not working			
--local track = humanoid.Animator:LoadAnimation(script:FindFirstChild("Death"..tostring(math.random(1, 4))))
                        local track = humanoid.Animator:LoadAnimation(anim)
			track:Play()
			track.Stopped:Wait() 
			anim:Destroy()
		end)
	end)

end)

So, I also put script like this in StarterCharacterScripts, in both ways script is called, but animation not playing, why it’s happened, where mistake?

if script is in startercharacterscripts, try

local character=script.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
humanoid.Died:Connect(function()		
  local anim = Instance.new("Animation", character)
  anim.AnimationId = "rbxassetid://"..animations[math.random(1, 4)]
  character.PrimaryPart.Anchored = true		
  local track =humanoid.Animator:LoadAnimation(script:FindFirstChild("Death"..tostring(math.random(1, 4))))
  local track = humanoid.Animator:LoadAnimation(anim)
  track:Play()
  track.Stopped:Wait() 
  anim:Destroy()
end)

Thanks for answer. I try put script in startcharacterfolder script, I understand that this should work, but the animation is not playing. The character is frozen for the duration of the animation, and then respawns. I can’t understand what is the problem :frowning:

you tried to do it without anchoring HumanoidRootPart?

try printing the time it took for the animation to play by saving current tick() before you start the animation the comparing it with the tick after the animation finished. What might happen is all animations are stopped or never played on dead humanoids

I try set to true and false…animation not playing. I try many death animation solution from this forum, in last roblox studio died animation not working. Where mistake?

maybe you don’t need to do

Humanoid.Animator:LoadAnimation()

just do it like this:

Humanoid:LoadAnimation()

you can put the arguments inside the parentheses.

1 Like

I add this to code:

local startTick = tick()
print("Start animation tick:", startTick)
local track = humanoid.Animator:LoadAnimation(script:FindFirstChild("Death"..tostring(math.random(1, 4))))
track:Play()
track.Stopped:Wait() 
print("Stop animation tick:", tick() - startTick)

and get this:
15:03:46.050 Start animation tick: 1681743825.2626426 - Server - Death:31
15:03:47.947 Stop animation tick: 1.897036075592041 - Server - Death:35
So animation is started and runnnig, but not displayed.
Ok, humanoid is die all animation it’s stopped and never playing on dead,
but how show animation for this event, if “Died” event not suitable?

it’s same, but:
Humanoid:LoadAnimation() is depricated
(Humanoid | Roblox Creator Documentation)

roblox says use this:
Humanoid.Animator:LoadAnimation()