Please bear in mind that I'm a beginner scripter. I started to learn how to script a few days ago.
I have a script that tries to make an NPC to have a death animation when its humanoid health reaches the value 0. However, it doesn't work and I tried everything I know to fix it.
local hum = script.Parent:WaitForChild("Humanoid")
if hum then
print("Success")
else
print("No Humanoid")
end
local humanim = hum:LoadAnimation(script:FindFirstChildOfClass("Animation"))
local deathanimation = hum:LoadAnimation(script:FindFirstChildOfClass("Animation"))
if humanim then
humanim:Play()
humanim.Looped = true
end
local function deathanim()
local death = script.Parent.Script.Died --Died is an animation
humanim.Looped = false
humanim:Stop()
death:Play()
print("Death animation played!")
end
if hum.Health == 0 then
deathanim()
end

1 comment
Oh and by the way, the script your using Is outdated, Its due to Humanoid:LoadAnimation() being Deprecated (Meaning It doesn't work on new work (Example: Using a Deprecated script on a roblox avater to make It jump,move,etc)