How to make damage animation

can you tell me how to make it so that when you damage a player or a dummy they will have an animation of what you damage them: for example:
(Game AUT)

5 Likes

You want to play different animation depending on how much damage they took or only one certain animation whenever they take damage? I don’t really get it but here’s what you can do

-- Serverscript inside dummy or Localscript inside StarterCharacterScripts
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

local AnimationObject = PATH_TO_ANIMATION
local LoadedAnimation = Humanoid:LoadAnimation(AnimationObject)

local oldHealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function()
    if oldHealth > Humanoid.Health then
        print("Humanoid took " .. oldHealth - Humanoid.Health .. " damage")
        LoadedAnimation:Play()
    end
    oldHealth = Humanoid.Health
end)
6 Likes

well, I want there to be different dependences on damage, but if I fail, then one animation will be good, too

Thanks!!

If you want to play different animations then make a table with damage value as a key and loaded animation as loaded animation like this:

local DamageAnimations = {
    [10] = LoadedAnimation1;
    [25] = LoadedAnimation2;
    [50] = LoadedAnimation3;
}

local function FindAnimation()
    local difference = oldHealth - Humanoid.Health
    local anim
    for i,v in pairs(DamageAnimations) do
        if difference >= i then
            anim = v
        end
    end
    return anim
end

local AnimationToPlay = FindAnimation()
AnimationToPlay:Play()

I hope this helped :slightly_smiling_face:

5 Likes

Thxxx so much. in what i like the roblox dev community :>

No problem! If my reply was helpful please don’t forget to mark it as “Solution” so other people can see this topic has been already solved

No problem :))))))))))))))))))))

can you help me i have errors :(((

Helloo bro??? :frowning:

You have to declare those variables for them to work, he left just names so you know what the variables are referring to. oldHealth is the player health before getting damaged, Humanoid.Health is the player’s current health after they have been damaged.

2 Likes

what if I have different health and damage for each character?? :frowning:

Oh lol im stupid i dont saw this post sorry for annoying.

Damage stays the same regardless, each attack should have a set damage. You get the health for each player by doing.

--If local script do
local player = game.Players.LocalPlayer
--If server script do 'local player = ' then a path to the player using whatever it is you are doing in the server script, for example using the player function parameter when a player clicks a ClickDetector and using that
local health = player.Character.Humanoid.Health

Thx bro :slight_smile: :relaxed:

hello sir i have problems again lol (check output)