Animations still playing when you sell an item

So whenever i would sell an item that i was holding, the animation would keep playing even though the script deleted the animations and tool

local prox = script.Parent
local amount = 3000

prox.Triggered:Connect(function(player)
	local GUN1 = player.Character:FindFirstChild("AKS-74U")
	local animations = GUN1:FindFirstChildOfClass("Animation")
	if GUN1 then
		player.leaderstats.Cash.Value += 3000
		animations:Destroy()
		GUN1:Destroy()
	end
end)

Any solutions would be greatly appreciated, thanks!

1 Like

You’ll need to stop the AnimationTrack using Stop().

More info here:

1 Like

Could you maybe explain how to use these, im not so familliar with animationtracks and stopping

1 Like

The first link explains everything you need to know about animations. You stop an animation the same way you start it, but with Stop() instead of Play().

1 Like

i’ve already tried using an animation track though, is there any other solution, this is what i did

local prox = script.Parent
local amount = 3000

prox.Triggered:Connect(function(player)
	local GUN1 = player.Character:FindFirstChild("AKS-74U")
	local animations = GUN1:FindFirstChildOfClass("AnimationTrack")
	if GUN1 then
		player.leaderstats.Cash.Value += 3000
		animations:Stop()
		GUN1:Destroy()
	end
end)
1 Like

You may have to do Stop(0) actually. But make sure you’re getting the correct animation as well.

Here’s an example of stopping all animations:

	for _, track in pairs(animator:GetPlayingAnimationTracks()) do
		track:Stop(0)
	end
1 Like

how would i implement this into my code?

1 Like

You’d put it where you want the animation(s) to stop. But this is where my help will have to end. The goal of this forum is to provide direction rather than answers (with some exceptions). Make sure to look through the references I have given and try to figure the rest out on your own.

oh alright, thanks i guess ;-;

1 Like