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
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!
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.
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)
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.
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.
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