Hi there! In the video, I’m showing an issue I’m having. When I replace one Tool with another, the new Tool keeps the Stand or Walk animations of the old one.
I know this happens because destroying the Tool breaks any connections and Tool.Unequipped dont have enough time to do its function. I did some research and saw someone use the Tool.Destroying function, which runs a function before the Tool is destroyed, but it didn’t work for me, or maybe I didn’t use it correctly…
I also had another question: what’s the best and most efficient way to manage all the animations for a Tool?
PD: When the second PART is touched, the tool is unequipped correctly because I use Humanoid:UnequipTools, but having to put a Wait or Task.Wait delays the process too much before I can then use Tool:Destroy.
The way I fixed this myself in the past was by getting all the playing animation tracks and stopping them.
local Animate = char:WaitForChild("Animate")
local Humanoid = char:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
for _, track in pairs(Animator:GetPlayingAnimationTracks()) do
track:Stop(0)
end
I agree with @Dutch_VII’s solution. I recommend that instead of stopping all animations, check for the animation name, then stop it. It should look like this:
for _, track in pairs(Animator:GetPlayingAnimationTracks()) do
if track.Name ~= "AnimTrack" then continue end -- change "AnimTrack" to you animation track name
track:Stop()
end