This script plays one of two animations when a player loses HP. For some reason, sometimes the animation doesn't load and i get the error "Animation has to be a descendant of humanoid". It is only sometimes and it's really bothering me. The script is a Local script inside of the starter pack
thanks for reading
local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
Player.CharacterAdded:connect(function(character)
char = character
hum = char:WaitForChild("Humanoid")
end)
if not hum.Parent then
repeat wait(0.2) until hum.Parent
end
local stan = Player:waitForChild("NonSave"):waitForChild("Stun")
local animTrack1 = hum:LoadAnimation(script:WaitForChild("oof"))
local animTrack2 = hum:LoadAnimation(script:WaitForChild("oof2"))
health = hum.Health
hum.Changed:connect(function()
if hum.Health < health and hum.Health > 0 then
local run = math.random(1 ,2);
if run == 1 then
animTrack1:Play()
stan.Value = true
hum.WalkSpeed = 8
wait(1)
stan.Value = false
hum.WalkSpeed = 16
else if run == 2 then
animTrack2:Play()
stan.Value = true
hum.WalkSpeed = 8
wait(1)
stan.Value = false
hum.WalkSpeed = 16
end
end
health = hum.Health
end
end)
