Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does the animation not stop even though :Stop() is called?

Asked by 3 years ago

I am trying to make a trash can that you can push around and I'm stuck on the idle animation. This is the code:

01isPushed = script.Parent.Pushing
02proximity = script.Parent.BodyAttach.ProximityPrompt
03idleAnimation = script.Parent.BodyAttach.Idle
04 
05function onTrigger(player)
06    if isPushed.Value == false then
07        local character = player.Character
08        local humanoid = character:WaitForChild("Humanoid")
09        local animator = humanoid:WaitForChild("Animator")
10        local animateScript = character:WaitForChild("Animate")
11        defaultAnim1 = animateScript.idle.Animation1.AnimationId
12        defaultAnim2 = animateScript.idle.Animation2.AnimationId
13        animateScript.idle.Animation1.AnimationId = idleAnimation.AnimationId
14        animateScript.idle.Animation2.AnimationId = idleAnimation.AnimationId
15        for i,track in pairs(animator:GetPlayingAnimationTracks()) do
View all 44 lines...

As you can see there is a loop in both cases that should stop all animations that are playing. But it doesn't stop the idle animation and it only changes if the character moves and becomes idle again.

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I think in line 16 and 33, you put track:Stop(0)when it should be track:Stop() If you remove the zero then your script will be working fine.

0
I tried that, but it didn't change anything. Also :Stop() and :Stop(0) should theoretically do the same thing. vonotige 49 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Instead of stopping all animations on the player, I instead opted to play the idle animation until the player moves. This is done by checking if humanoid.MoveDirection is not equal to 0,0,0

Log in to vote
0
Answered by
1JBird1 64
3 years ago

instead of getting the animation tracks from the animator, get it from the humanoid instead.

so it would probably look like this:

1for i,track in pairs(humanoid:GetPlayingAnimationTracks()) do
2 if track.Animation.AnimationId == “rbxasset//insert_animation_id” then
3  track:Stop()
4 end
5end

Answer this question