Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to stop animation when weapon is removed?

Asked by 5 years ago

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

Log in to vote
1
Answered by
poke7667 142
5 years ago

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().

Ad
Log in to vote
0
Answered by
pwx 1581 Moderation Voter
5 years ago

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

Tool.Unequipped:Connect(function()
    anim:Stop()
end)
0
There we go I wrote that but instead of stop I used destroy or delete. But yeah that should work. Screaming_Monkeys 4 — 5y

Answer this question