How to detect an animation stopping from a different script?

Hello, as stated in the title I am currently dealing with animations and scripts. I have one server script that plays an animation and also I have second server script that should trigger some logic after it waits for the animation to stop. A few key points are that I can not just simply add a task.wait() before the logic of the second script and fill it with the duration of the animation since the script that plays the animation also sometimes intensionally interupts it by stopping it early.
I have tried turning the animation into a global variable with _G. and then using a .Stopped:Wait() inside the second script now that it has access to the same animation instance, however it seams that _G. is not great for such a timing sensitive detection as the one that the second script requires so the script would sometimes work and sometimes it would not, the result would just vary from one play testing session to another even when I have not touched any of the scripts. I am looking for a way to detect the animation stoping inside the second script with something similar to .Stopped:Wait() since it does not complicate the code needlessly. Is there any standard reasonable way people detect animations stopping from within a different script? This is basically what I am looking for.

Stopped only works if :Stop is called on the animation. Can you provide code?

Loop through the animation tracks inside the other script and get the name of the animation (for example: Punch) and check if the name matches the name Punch, then connect .Stopped event to that and do what u need inside the event.

for _, animationTrack in ipairs(humanoid:GetAnimationTracks()) do
        if animationTrack.Name == "Punch" then
            animationTrack.Stopped:Connect(function()
                -- do smth here
            end)
        end
end

Ok for context this is inside the script tha plays the animation

local loader = stand.AnimationController:LoadAnimation(stand.kcbarage)

		_G.BarageInitialPunch = loader 

		loader:Play()

and this is inside the script that should wait for it to stop or get interupted

	local BarageInitialPunch = _G.BarageInitialPunch

	--Do the move	

	if standMainBody then
		BarageInitialPunch.Stopped:Wait()
             -- logic here 
            end   

However the current setup with a global variable _G works only whenever it feels like it inside the sript that monitors for the animation stopping dues to _G. not being great timing wise ,so I need a better solution

wait I dont think the animationTrack.Stopped works if the animation was triggered/played inside a different script. For context this is inside the script tha plays the animation

local loader = stand.AnimationController:LoadAnimation(stand.kcbarage)

		_G.BarageInitialPunch = loader 

		loader:Play()

and this is inside the script that should wait for it to stop or get interupted

	local BarageInitialPunch = _G.BarageInitialPunch

	--Do the move	

	if standMainBody then
		BarageInitialPunch.Stopped:Wait()
             -- logic here 
            end   

However the current setup with a global variable _G works only whenever it feels like it inside the sript that monitors for the animation stopping dues to _G. not being great timing wise ,so I need a better solution

It’s triggered and you can get it through :GetAnimationTracks()

Ok, but then the idea is that I would have the code that you gave me inside the script that monitors for when the animation stopps and I would put all of the loguic that was previously bellow the “BarageInitialPunch.Stopped:Wait()” inside of it ? Or am I suppposed to have it inside the animaion player script and send some kind of signal to the second script somehow and if so ,how am I supposed to do that in a way that would be as fast as possible?

Yes, do it exactly like this way.