Attempt to index nil with "Ended"

I get this error:

Players.octav20071.Backpack.Punch:59: attempt to index nil with ‘Ended’

On this lines of code:

if TargetHumanoid:FindFirstChild("Monster") then
					PunchEvent:FireServer(TargetHumanoid,_Damage.Value)
					local Anim = Humanoid.Animator:LoadAnimation(ChosenAnim)
					Anim:Play()
					PunchSound:Play()
					TheGame:AnchorCharacter(Player)
					Anim.Ended:Wait() -- error
					TheGame:UnanchorCharacter(Player)

Why though? Help?

2 Likes

Anim.Stopped:wait()

CHARACTERS

1 Like

Instead of “Ended”, it is “Stopped” (Animation Track API)

2 Likes

@SimonGLOW @BuilderDolphin

attempt to index nil with ‘Stopped’
image

1 Like

How did you modify the code? Did you add it correctly?

remove the .Animator from the script

if TargetHumanoid:FindFirstChild("Monster") then
					PunchEvent:FireServer(TargetHumanoid,_Damage.Value)
					local Anim = Humanoid.Animator:LoadAnimation(ChosenAnim)
					Anim:Play()
					PunchSound:Play()
					TheGame:AnchorCharacter(Player)
					Anim.Stopped:Wait()
					TheGame:UnanchorCharacter(Player)
-- while ChosenAnim is
				local ChosenAnim = PunchAnims[math.random(1, #PunchAnims)]

That would mean to use a deprecated function. Can’t do that. And I tried too, same result.

if you remove the things in between the :Play() and the .Stopped will it give the same error?

What things do you mean?

these
PunchSound:Play()
TheGame:AnchorCharacter(Player)

I don’t see why that would affect anything but…

nothing changed

Since I don’t see it said, your error means that Anim is nil. I don’t see the problem offhand though.

is the chosen anim before playing the animation?

Well, of course.

I have added this:

print(Anim,Anim.Name)
Anim.Stopped:Wait()

And it printed was, well…
Nothing.
image
What is this??

just do print(Anim.Name) I wanna see if the anim is nil

Same result as the above.

and the animation does play right?

Yes, it does. I am not sure what is happening.

ok we’ll do an alternative way do this :
wait(anim.Length) instead of Anim.Stopped:Wait()