I've got a script that plays one of two animations when the player loses health. the animations are inside of the script and they are named oof and oof2. the script is a local script inside of starterpack.

Sometimes the console will say "oof is not a valid member of LocalScript", and the animation won't play. it is kinda annoying and It's really hindering progress on the game.

any idea what's wrong with it?

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.oof)
local animTrack2 = hum:LoadAnimation(script.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 = true
    hum.WalkSpeed = 8
    wait(1)
    stan = false
    hum.WalkSpeed = 16
	else if run == 2 then
	animTrack2:Play()
	stan = true
	hum.WalkSpeed = 8
	wait(1)
	stan = false
	hum.WalkSpeed = 16
	end
	end
health = hum.Health 
end
end)

thanks for reading

3 comments

1

local animTrack1 = hum:LoadAnimation(script:WaitForChild("oof")) local animTrack2 = hum:LoadAnimation(script:WaitForChild("oof2"))

1

oops, excuse that, at line 13 and 14 try using a WaitForChild for both of the oofs, example: script:WaitForChild("oof")

0

Thanks, I tried that already but it broke the whole thing. (at least i thought) It was a different error breaking it, I've fixed that and now WaitForChild() works.