Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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:

isPushed = script.Parent.Pushing
proximity = script.Parent.BodyAttach.ProximityPrompt
idleAnimation = script.Parent.BodyAttach.Idle

function onTrigger(player)
	if isPushed.Value == false then
		local character = player.Character
		local humanoid = character:WaitForChild("Humanoid")
		local animator = humanoid:WaitForChild("Animator")
		local animateScript = character:WaitForChild("Animate")
		defaultAnim1 = animateScript.idle.Animation1.AnimationId
		defaultAnim2 = animateScript.idle.Animation2.AnimationId
		animateScript.idle.Animation1.AnimationId = idleAnimation.AnimationId
		animateScript.idle.Animation2.AnimationId = idleAnimation.AnimationId
		for i,track in pairs(animator:GetPlayingAnimationTracks()) do
			track:Stop(0)
		end
		local playerTorso = player.Character:WaitForChild("UpperTorso")
		M6D = Instance.new("Motor6D", playerTorso)
		M6D.Name = "TrashGrip"
		playerTorso.TrashGrip.Part0 = playerTorso
		playerTorso.TrashGrip.Part1 = script.Parent.BodyAttach
		proximity.Style = Enum.ProximityPromptStyle.Custom
		isPushed.Value = true
	else
		local character = player.Character
		local humanoid = character:WaitForChild("Humanoid")
		local animator = humanoid:WaitForChild("Animator")
		local animateScript = character:WaitForChild("Animate")
		animateScript.idle.Animation1.AnimationId = defaultAnim1
		animateScript.idle.Animation2.AnimationId = defaultAnim2
		for i,track in pairs(animator:GetPlayingAnimationTracks()) do
			track:Stop(0)
		end
		M6D:Destroy()
		M6D = nil
		proximity.Style = Enum.ProximityPromptStyle.Default
		isPushed.Value = false
	end
end

proximity.Triggered:Connect(function(player)
	onTrigger(player)
end)

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

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.

1 comment

0

I tried that, but it didn't change anything. Also :Stop() and :Stop(0) should theoretically do the same thing.

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

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

so it would probably look like this:

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

This discussion is preserved as it was. New answers, comments, and votes are closed.