Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to stop animation when weapon is removed?

So I was able to get the weapon animations to work but whenever I remove the weapon the animation stays in place. I'm not sure how I can stop the animation when the weapon is unequipped. Here is the script

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid")
local anim = h:LoadAnimation(script.Parent:WaitForChild("Animation"))

local tool = script.Parent

tool.Equipped:Connect(function()
	anim:Play()
end)

2 answers

✓ Accepted answer

You need to use the Unequipped event to do this. Pretty similar to what you have in the Equipped event but instead use unequipped and have the line: anim:Stop().

This one is pretty self-explanatory. Use a .Unequipped event.

Tool.Unequipped:Connect(function()
	anim:Stop()
end)

1 comment

0

There we go I wrote that but instead of stop I used destroy or delete. But yeah that should work.

This discussion is preserved as it was. New answers, comments, and votes are closed.