Animations are kept when destroying Tools

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.

1 Like

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

Then just loading the original animations again.

    Animate.idle.Animation1.AnimationId = "rbxassetid://10862959383"
	Animate.idle.Animation2.AnimationId = "rbxassetid://10862959383"
	Animate.toolnone.ToolNoneAnim.AnimationId = "rbxassetid://10804079059"

Now this was a solution I used over 2 years ago; so I’m unsure if there is a more elegant solution or not.

3 Likes

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
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.