Animation stops 5 seconds after its supposed to turn off?

Okay, I’m having an issue with animations. It stops when I need it to stop, but it waits 5 seconds for it to go stop and i dont know what the issue is. This is simple code, if the Blocking gets destroyed it waits 5 seconds and then stops. Does anybody know what the issue is? I dont have any task.wait()s in the code.

while task.wait() do
	if script.Parent:FindFirstChild("Blocking") then
		 loader = script.Parent.Humanoid.Animator:LoadAnimation(script.Animation)
	loader:Play()
	else
		loader:Stop()
	end
end

I dont have any task.wait() s in the code.

Not sure if this has any relation to the problem but you do:

while task.wait() do
1 Like

Not much to go on there but guessing you are using an animation on loop while attacking a “Blocking” and the “Blocking” is some sort of breakable wall assuming with something like HP which depletes before it breaks? [If it’s a PvP thing need more info.]

You could add in another simple variable and do something like if Blocking HP = 0 then loader:Stop() instead of the else, might make it more responsive. Without also seeing the blocking code hard to say.

Everything does look right so I’d assume something is off with your Blocking

Is Blocking a BoolValue or a part you created?

I’m pretty sure that it’s because the script loads and plays the animation every frame without stopping the previous one
which means that when Blocking gets destroyed, the script stops the newest loaded animation but the previous ones are still playing

I would much rather use a child added and a child removed events to detect when blocking is added or removed