Animation not stopping when using Animation:Stop()

robloxapp-20230706-0819598.wmv (2.0 MB)

local Player = game.Players.LocalPlayer
local Animation = script.Parent.Holding
local Axe = script.Parent
local Animator
local LoadedAnimation
Axe.Equipped:Connect(function(mouse)
	Animator = Player.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
	LoadedAnimation = Animator:LoadAnimation(Animation)
	LoadedAnimation:Play()

end)
Axe.Destroying:Connect(function()
	LoadedAnimation:Stop()
end)

LoadedAnimation:Stop() doesn’t do anything and the character is still stuck in that pose

3 Likes

Perhaps instead try looping through all the animations being played and end each of them. The normal animations for the character (like walking, idle etc) will resume, but the one you’re trying to stop shouldn’t.
Inside of the last function, try putting:

for i, v in pairs(Player.Character.Humanoid:GetPlayingAnimationTracks()) do 
	wait()
	v:Stop()
end

Did you tried to do it using:

Axe.Unequipped:Connect(function()
	LoadedAnimation:Stop()
end)
1 Like

What is the priority of the animation you are adding to your pickaxe?

Can you see if Axe.Destroying does something for e.g:

Axe.Destroying:Connect(function()
    print("Destroying")
	LoadedAnimation:Stop()
end)

The Axe doesn’t get destroyed when unequipping. It moves it back to your backpack, unless you’ve created your own inventory system.

If you edit the code to say the following, it should work, assuming theres no issue with your animation priority.

Axe.Unequipped:Connect(function()
	LoadedAnimation:Stop()
end)

If that doesn’t solve your issue, go through the normal debugging steps, check to see if the event fires, either by using breakpoints or stick a print statement within the scope of that chunk of code.

You could also try using the .Changed signal to check if the parent on the tool has changed. This is more long winded and is like putting a plaster/bandaid over a stab wound, it’ll cover up an issue but the underlying issue will still be there

Axe.Changed:Connect(function(Prop)
	if Prop == "Parent" then
		LoadedAnimation:Stop()
	end
end)

Some other things to note with the :Stop() event, you can add a fade-out time parameter to fade out the animation over a period of time. That was a useful thing I didn’t learn until the last project I did. Good thing to know.

The axe is unequipped by destroying it, which sends a copy to replicated storage for later use.

Same thing I said to Crygen, the axe is unequipped by destroying it, which sends a copy to replicated storage for later use. Yes it is a custom inventory system

Nothing new happens with this loop :confused:

The animation priority is Action3.

Try determinating the animator and the loadedanimation variables before the function. And, as i know, when you unequip a tool roblox moves it to the backpack, so you should just use Axe.Unequipped imo.

1 Like

I found it. There’s a weird case with my equipping system where it adds the tool to the player, then to the backpack, then back into the player (because just adding it the player didn’t automatically put it in the players had and forcing the tool to equip caused other issues. I don’t know why), so the animation was being played twice, essentially meaning that the script was only stopping half of what it needed to. I added a cooldown to the equip part so everything is good now

local Player = game.Players.LocalPlayer
local Animation = script.Parent.Holding
local Axe = script.Parent
local Animator = Player.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
local LoadedAnimation  = Animator:LoadAnimation(Animation)
local Cooldown = false
Axe.Equipped:Connect(function(mouse)
	if Cooldown == false then
		Cooldown = true
		LoadedAnimation:Play()
		wait(.3)
		Cooldown = false
	end
end)
Axe.Destroying:Connect(function()
	LoadedAnimation:Stop()
end)

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