How to make Animation's play random when taken damage

Hello! I am trying to make different animations play through a folder while I take Damage form another player. right now I have a script that plays the one animation but I want to loop different animations when hit if anyone can help me thank you.

Here’s what I have so far

Script

try assigning a variable to a random number

example:
local value = math.random(1,3)

if value == 1 then
--play anim 1
elseif value == 2 then
--play anim 2
elseif value == 3 then
--play anim 3
end
2 Likes

I understand what you are saying but idk how to set it up properly to also make the health go off after or make the animation play?

m

Help

Also in the game, its not in startercharacterscripts, each script in startercharacterscripts are located in the character. I would instead recommend putting the animation folder in replicated storage and just leave the script in startercharacterscripts.
try implementing my example script like this:

if LastKnownHealth > Humanoid.Health then
print("Playing") 
local value = math.random(1,3) --change the 3 to how many animations there are
if value == 1 then
script.Parent.Parent.ReplicatedStorage.animationFolder.Ani:Play()
end
end
1 Like

Thank you very much I will note that next time i thought they just had to be in CharacterScripts cause it’s coming directly from the character

image

image

For some reason does not work it doesn’t print errors either

try doing this

if value == 1 then
local anim = Humanoid:LoadAnimation(game.ReplicatedStorage.Animation.Ani)
anim:Play()
end

Very strange still doesn’t work :confused:

I see the problem, i have edited my previous response. See if it works.

Odd idk if it’s Outdated script or what but it just won’t work

try this script

    local hum = script.Parent.Humanoid
    local currenthealth = hum.Health
    hum.HealthChanged:Connect(function(health)
    if health>currenthealth then
    print("Playing")
    local value = math.random(1,3)
    if value == 1 then
    local anim = hum:LoadAnimation(game.ReplicatedStorage.Animation.ani)
anim.Priority = Enum.AnimationPriority.Action
    anim:Play()
    end
    currenthealth = health
    end
    end)

Sadly still doesn’t work :grimacing:

where is the script located? Because I’m assuming its in startercharacterscripts.

Yes it is in StarterCharacterScripts.

ive edited my previous script to hopefully make it work

Yeah bro i’m really not sure to be honest this should work and I don’t see any other way why it wouldn’t

does your animation even have an animation id? go to view → properties which opens the properties menu. Then highlight the animation and check its animation id.

Yes it does I have tested multiple animation id’s

image

Is is an r6 or an r15 aniation?

1 Like

also i just realized that i made a mistake

it should be:

if health<currenthealth then

and not

if health>currenthealth then

2 Likes