Animation on Death

For a while, I’ve been creating a wizard101/toontown - esque game, in which you have battles against enemies (+ a multitude of other stuff, but that’s irrelevant). At the end of the battle, once (/if) the enemy dies, currently, they simply break apart and fall to the floor, as shown in this clip:

Instead of this, which obviously looks ludicrous, it would clearly be better to play an animation once the enemy dies. Similar to a system that wizard101 does, as shown in this youtube clip:

The problem is, once the enemy dies, its parts uncontrollably break apart, and once the humanoid dies, animations can’t play upon it. I was just curious if there would be a more un-hacky way to play an animation once it dies, other than creating a separate health system.

TL;DR how the heckity heck do I allow the playing of animations once a humanoid dies, instead of just limbs breaking apart.

13 Likes

I don’t know how well it’d work in this current situation, but if you could try making another fake character in the place where the main character died, and playing the animation on that one instead once the other one dies.

1 Like

Don’t use Humanoids if you want a custom thing like this. Well, don’t change the health of Humanoids to 0. Use an IntValue object or handle it via your scripts.

3 Likes

I’ve made something like this a few years ago. I can’t recall exactly how I did it - so don’t grab your pitchfork if it doesn’t work - but you could try something like this:

  1. Disable Enum.HumanoidStateType.Dead
    – This will prevent the character from falling apart upon death.
  2. Check for Humanoid.HealthChanged to see when the character should die.
  3. Upon Health == 0, play your animation.
  4. When the animation is done playing, enable Enum.HumanoidStateType.Dead again and kill the player in case he regained some health in the meantime.
  5. Upon respawning, once again disable Enum.HumanoidStateType.Dead

Some example code; not tested!

Plr.CharacterAdded:Connect(
    function(char)
        local Hum = char:WaitForChild("Humanoid")
        Hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
        local DeathAnim = Hum:LoadAnimation(YOUR_ANIMATION)

        Hum.HealthChanged:Connect(
            function()
                if Hum.Health <= 0 then
                    DeathAnim:Play()
                end
            end
        )

        DeathAnim.Stopped:Connect(
            function()
                Hum.Health = 0
                Hum:SetStateEnabled(Enum.HumanoidStateType.Dead, true)
            end
        )
    end
)
50 Likes

Perfect! Just what I needed. I’ll have to test this asap haha :stuck_out_tongue: