AnimationTrack.Stopped event not working

I am trying for this part of my script to detect when the animation finishes playing.

Oddly, it just doesn’t detect it. I don’t think it’s the animator or Attack1AnimationLoaded variables because in a upper part of my script I used them to play the animation and it worked out perfectly fine.

local animator = player.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator")

    local Attack1AnimationLoaded = animator:LoadAnimation(Attack1Animation)
        
    Attack1AnimationLoaded.Stopped:Connect(function()
		print("E")
			if Activated then
				print("nothing")
				Activated = false
			end
		end)
1 Like

So anyways the animation didn’t even get played, which is why it wasn’t able to check its connection with the Stopped event

Try this LOL

local animator = player.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator")

    local Attack1AnimationLoaded = animator:LoadAnimation(Attack1Animation)
    Atttack1AnimationLoaded:Play()

    Attack1AnimationLoaded.Stopped:Connect(function()
		print("E")
			if Activated then
				print("nothing")
				Activated = false
			end
		end)

I have it playing above it. I’ll get the larger part, I’ll shorten it a bit. Does it need to be in the very same bit, like can it not be separated by an end?

Script
		local animator = player.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator")
		if animator then
			Attack1Animation.AnimationId = ScriptRequire.Attack1["Attack1_AnimationId"]
			
			local Attack1AnimationLoaded = animator:LoadAnimation(Attack1Animation)
			Attack1AnimationLoaded:Play()
			Attack1AnimationLoaded.Priority = 1
			
			local IntValue = script:FindFirstChild("IntValue")
			IntValue.Value = ScriptRequire.Attack1["Attack1_Damage"]
			local DamageValue = IntValue.Value
			DamageValue = ScriptRequire.Attack1["Attack1_Damage"]
			
			AttackRemoteEvent:FireServer(DamageValue)
		end
		
	local Attack1AnimationLoaded = animator:LoadAnimation(Attack1Animation)
		Attack1AnimationLoaded.Stopped:Connect(function()
			print("E")
			if Activated then
				print("no")
				Activated = false
			end

The thing is, it might be due to the fact that you’re already creating a new local variable which is basically resetting the Animation & waiting for it to stop again (But since you played it earlier in your script & redefined it, it won’t be able to detect it stopping)

Could you try this and see if anything changes?

        local Attack1AnimationLoaded
		local animator = player.Character:FindFirstChild("Humanoid"):FindFirstChild("Animator")

		if animator then
			Attack1Animation.AnimationId = ScriptRequire.Attack1["Attack1_AnimationId"]
			
			Attack1AnimationLoaded = animator:LoadAnimation(Attack1Animation)
			Attack1AnimationLoaded:Play()
			Attack1AnimationLoaded.Priority = 1
			
			local IntValue = script:FindFirstChild("IntValue")
			IntValue.Value = ScriptRequire.Attack1["Attack1_Damage"]
			local DamageValue = IntValue.Value
			DamageValue = ScriptRequire.Attack1["Attack1_Damage"]
			
			AttackRemoteEvent:FireServer(DamageValue)
		end
		
	if not Attack1AnimationLoaded then
        return
    end
		Attack1AnimationLoaded.Stopped:Connect(function()
			print("E")
			if Activated then
				print("no")
				Activated = false
			end
1 Like

Yea, I have to move the end from the upper part, so I don’t have to make a new variable, but when I remove it, it still doesn’t fire for some reason, I don’t think it can be because of a WaitForChild yield, since FindFirstChild also doesn’t fix it. The event should still listen and fire right? Even though it’s in a ContextAction Binded function?

Just to make sure, I can use AnimationTrack.Stopped locally right?

This event can be used locally yes

Sorry, thanks for the help, I realized I was dumb and forgot to delete the new variable after removing the end lol. I need to start using more of my brain capacity.