How do i make a death animation play when a particular model is touched by a player?

I’m trying to make it so if you touch something (specifically a model) like a lava part or spikes, a death animation dedicated to what you touched will play instead of a player breaking to pieces. I’m having lots of trouble trying to figure this out and i tried searching for solutions and couldn’t find much. h e l p .

2 Likes

Simply turn BreakJointsOnDeath in a humanoid to false, then that lets you play animations while… dead…

2 Likes

It would be something like this:

local lava = workspace.Lava --- Your lava brick.

lava.Touched:Connect(function(part) --- The function that starts when the brick is touched. "part" is the instance that touches the lava brick itself.
   local humanoid = part.Parent:FindFirstChild("Humanoid") --- Checks to see if this is a player object.
   if humanoid and humanoid.Health > 0 then
         local player = humanoid.Parent -- The player's character.
         player.BreakJointsOnDeath = false -- This keeps the player from dying.
         humanoid.Health = 0
         local deathAnim = humanoid:LoadAnimation(player.Death) --- Replace "player.Death" with the actual location of where your death animation is located.
         deathAnim:Play() -- Play animation.
    end
end)
2 Likes

@BruiseIgnio, i advise you to put the animations in the trap, because if the Certain Trap kills someone, the animations in the Humanoid will copy, play and then destroy them. Why do I recommend it: I say that if @Brodycoolsquid wants to play a different animation for each trap and not the same animation for each trap (for example, if his character falls in lava that burns to dust thanks to a blender animation or if he falls in quicksand that he first falls a little bit slowly and then suddenly disappears very quickly in the sand itself. As you can see here, they are two different animations, you don’t want your character to burn up when he falls in the sand). I can do that myself: Yes, but it’s your code, and I don’t want to steal the solution.

2 Likes

That’s a good idea, but that’s why I said for op to get the animation wherever it may be located; I granted that freedom to him.

2 Likes