Can't stop animation?

  1. What do you want to achieve? I want to know what’s wrong with my script or my game.

  2. What is the issue? The animation won’t stop playing, I already put :Stop() but it doesn’t stop. Currently can’t provide pictures.

  3. What solutions have you tried so far? I haven’t even seen a tiny bit of the problem I have being talked about.

		if posing == false and isAttacking == false then
			print("m")
			posing = true
			
			Animations.pose:Play()
			Animations.spose:Play()
			wait(0.5)
			Animations.posel:Play()
			Animations.sposel:Play()
		elseif posing == true and isAttacking == false then
			print("s")
			posing = false
			
			wait(0.5)
--			Animations.pose:Stop() (intentional)
--			Animations.spose:Stop() (intentional)
			Animations.posel:Stop()
			Animations.sposel:Stop()
		end
	end

Once the function is called, it prints “s” but the animation doesn’t stop. It keep playing forever. (Note that “Animations” is a table:

local Animations = {
			idle = Spirit:WaitForChild("HP"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("Idle"));
			pose = plr.Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("Pose"));
			spose = Spirit:WaitForChild("HP"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("SPose"));
			posel = plr.Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("PoseLoop"));
			sposel = Spirit:WaitForChild("HP"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("SPoseLoop"))
		}

)

16 Likes

I’m not sure if this would work, but you could try:

animation:Stop(0)

0 is usually considered as a ‘successful execution’, meaning that the funtion ran successfully :man_shrugging:

6 Likes

I might be wrong but I don’t think the Animation is being loaded upon compile and only when called. You need to ensure the animation you are loading is the same variable you use to stop it.

Try loading the animation within the first if statement, store it as a variable and call that same variable in the else if statement for stopping it.

3 Likes

Could you maybe show this table? And also depending on what you want to do you could maybe just set looping to false…

4 Likes

The dashes at the beginning of the line define the whole line as a note which the script would skip upon execution. I’m not sure if you put those there when you were posting, but if they are included in the script you should remove them.

4 Likes

yes check if comment is intentional
if intentional, check if any of the animation is still playing by IsPlaying bool
some of the animation should be playing so you know what to stop
if not result in any anim playing,
the
¯\_(ツ)_/¯

3 Likes
local Animations = {
			idle = Spirit:WaitForChild("HP"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("Idle"));
			pose = plr.Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("Pose"));
			spose = Spirit:WaitForChild("HP"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("SPose"));
			posel = plr.Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("PoseLoop"));
			sposel = Spirit:WaitForChild("HP"):LoadAnimation(Spirit:FindFirstChild("Animations"):FindFirstChild("SPoseLoop"))
		}

I have also tried messing with Looped value of the animation but it also didn’t work.

3 Likes

It is intentional, sorry for not stating and confusing you.

2 Likes

After stopped, the IsPlaying bool is false but the animation continues to play.

2 Likes

Was it looped in the Animation Editor? I had a similar problem where I accidentally left the Looped property on in there and it wouldn’t stop, even if I called :Stop().

3 Likes

I tried manually disabling the Looped property through scripting though, also the animation is supposed to be looped.

1 Like

From wiki

  1. The first argument is simply the time roblox takes to interpolate from the playing animation’s pose to the default/next-in-priority animation’s next pose. Setting it to 0 simply means you wish for no interpolation and the character to instantly continue doing other animations. Passing in more than one argument does nothing at all.
  2. 0 is considered a successful execution (in OS processes, let’s ignore the fact that this has absolutely nothing to do with Lua). Which means it would be a return value after the function finished executing. How would passing the return code as an argument influence the function… to work successfully?
  3. Stop is a void by Roblox definition. It won’t ever return anything and the only thing it can do to influence program execution is to throw an error. It does not have a return code, and it does not tell you if it worked successfully (unless it errors, in which case it didn’t).
5 Likes

Can you try doing print(Animations.pose1.IsPlaying) right before and right after the Stop line?

4 Likes

This is what I did:

		elseif posing == true and isAttacking == false then
			print("s")
			posing = false
			
			print(Animations.posel.IsPlaying)
			
			wait(0.5)
--			Animations.pose:Stop()
--			Animations.spose:Stop()
			Animations.posel:Stop()
			Animations.sposel:Stop()
			
			print(Animations.posel.IsPlaying)
		end
	end
end)

This is the output:

2 Likes

The track you’re trying to stop isn’t playing anymore at that point. A different animation track is causing issues. You can try the same printing procedure with spose1 to verify that that is not the track either. Regardless, it would really help if you told us which of your 5 tracks is playing when it shouldn’t be.

One possible reason is that your Animation instances have the wrong IDs.

3 Likes

Sorry for not stating it obvious. After triggering the function, it checks if posing is false and isAttacking is false (These works fine), then afterwards it’ll play “pose” and “spose” then afterwards it play “posel” and “sposel” (l stands for loop).
If did correctly, the outcome will look like this:


(The first time I wasn’t including pictures because I didn’t want to leak, but now I understand it is needed.)

And now, pose and spose already ended so it wasn’t needed anymore, so the only animations I need to stop are “posel” and “sposel” which both are supposed to looped.

And now the posing variable is true, once triggered again the function will stops “posel” and “spsoel” which both didn’t stop and that’s how this topic was made.

2 Likes

That makes more sense. I wouldn’t know why your code segment doesn’t work then (except that 100% verify and double check that all animation IDs and variable names match).

One thing to note is that it’s not needed to have a pose entry and a pose loop animation if the pose loop animation is a single, still pose. You can call track:AdjustSpeed(0) to freeze the pose entry animation at any point in time, then either Stop or AdjustSpeed(1) to go out of pose.

4 Likes

I’ll have a try, thanks for your tips.

2 Likes

It still did not work, I absolutely have no idea why now.

3 Likes

How/when are you calling the function? It might execute too often in which case the wait()s can mess up the timing. Try commenting them out.

Edit: I should note this is a debug fix and will cause unwanted behavior. If this ends up being the actual issue, you will need a different code

3 Likes