Animation not stopping

Hello everyone, I have a baseball bat and It has an idle animation and theres a part that deletes the baseball bat if you touch it, but if you touch the part while holding the bat the idle animation wont stop, I used Humanoid:GetPlayingAnimationTracks to get all the playing animation tracks and stopped them but for some reason the idle animation just keeps playing.

Part of the script that is supposed to stop the animation:

		local anims = Humanoid.Animator:GetPlayingAnimationTracks()
		for _,v in pairs(anims) do
			v:Stop()
		end

The code looks fine.

Is this idle animation ever supplied to the Animate script? That script will keep idle animations going. Other things you can try:

  • Confirm this code executes
  • Confirm the Humanoid has not changed since this script executed (you need to rebuild all humanoid scripts for each CharacterAdded)

Yep, i loaded the animation to animator inside the humanoid (Humanoid.Animator:LoadAnimation) do i need to load it to humanoid instead?

and yes i confirmed that this code executed but for some reason it wont work.

I’m not talking about the Animator. That is correct. Humanoid is depreciated.

There is a default Animate script that Roblox adds to Humanoids automatically to load preset animations for R6 and R15. You can save a copy and plug in your own animations. It’s a bit of an abomination…

If you don’t know what I’m talking about, you didn’t do any of that! :slight_smile:

The code runs, but doesn’t stop the animation. I’m pretty sure that means “anims” has nothing in it. Try:

print(#anims)

If it is 0 and the animation still plays, we are going to need to see how you set up Humanoid and load the animations.

It printed 3 (charsscharsssss)

I confirmed this section of code is virtually identical to my “stop all” code. I expect the problem to be elsewhere.

Let’s do a quick sanity check. How many animations did you expect to find? Is there a second animator? Can you post your load animation code?

The part that deletes the baseball bat also loads/plays an animation.
and if i come to your questions

I expected to find only 2.

My code: (inside the tool that plays the idle anim etc.)

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

if not Player.Character then
	Player.CharacterAdded:Wait()
end

local Humanoid = Player.Character:WaitForChild("Humanoid")
local anim1 = script.Parent.Animations.idle
local anim2 = script.Parent.Animations.swing
local idle = Humanoid.Animator:LoadAnimation(anim1)
local swing = Humanoid.Animator:LoadAnimation(anim2)

local EquipSound = script.Parent.Bat.Equip

script.Parent.Equipped:Connect(function()
	EquipSound:Play()
	idle:Play()
end)

script.Parent.Unequipped:Connect(function()
	idle:Stop()
end)

script.Parent.Activated:Connect(function()
	if script.Parent.CanSwing.Value == true then
		script.Parent.CanSwing.Value = false
		swing:Play()
		wait(3)
		script.Parent.CanSwing.Value = true
	end
end)

script.Parent.MaxHits.Changed:Connect(function()
	if script.Parent.MaxHits.Value < 1 then
		idle:Stop()
		swing:Stop()
	end
end)

sorry the code is like a bowl of spaghetti lol.

Oh another thing that I discovered, the idle animation that gets stuck is only visible for the client, not the server while the original animation is visible for both.

That’s something. Is this a local script or a server script?

Local script, if you are asking about the script that stops the anim its a server script

I use server scripts for all animations now, just because I store my animations server side. There are replication issues on Animation objects. That should not be the problem, as you grab the playing animation tracks.

I’d try making both local, or both server.

1 Like

Alright golgi but i have to do It tomorrow as I gtg now, I’ll inform you about the results tomorrow, thanks

No problem! That’s the fun thing about animation issues. It’s almost never “thats it! that’s the problem right there!”

1 Like

Unfortunately a local script didn’t work but I tried using Humanoid:UnequipTools() the player unequips the tool first so the idle anim stops, and it somehow worked xD Thank you for trying to help me

1 Like