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
Hello! I think I found a problem, the problem Is that you didn't had a Animator
Here Is the Instructions: 1. Add a NPC 2. Add a Animator Inside of the humanoid of NPC 3. Add a animation Inside of Animator 4. Add script 5. Type this:
local NPC = script.Parent ---The NPC local Animator = NPC.Humanoid.Animator ----Gets the animator local Animation = Animator.Animation while wait() do ----does a loop if NPC.Humanoid.Health == 0 then ---If the NPC has 0 health local AnimationTrack = NPC.Humanoid.Animator:LoadAnimation(Animation) ---We make a local varible that loads the animation AnimationTrack:Play() ---Plays the track (THE ONE BELOW ME IS OPTIONAL) wait(1) ----Wait 1 second NPC:Destroy() ---Despawns NPC end end
Btw I anchored the HumanoidRootPart or else the body parts will fall off