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

Cannot stop animation after unequipped tool?

I have been trying to make a two handed gun for my game using a animation, but i can't make it stop when i want it to. I'm stumped

Can anyone help? Thanks in advance

My last attempt(inside localscript):

script.Parent.Equipped:Connect(function()
    animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.GunIdle)
    animation:Play()
end)

script.Parent.Unequipped:Connect(function()
	animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.GunIdle)
    animation:Stop()
end)

Also would like to add, no errors are produces. Link to gif: https://gyazo.com/89aa581f12f434344febb75ce4149007

1 answer

✓ Accepted answer

You want to create and use LoadAnimation outside of these events so both event functions has the animation.

Also we want to wait for both the character and the humanoid before using LoadAnimation

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

script.Parent.Equipped:Connect(function()
    anim:Play()
end)

script.Parent.Unequipped:Connect(function()
    anim:Stop()
end)

4 comments

0

Also here's my set up of the gun: https://gyazo.com/2c72b473fe697ae71c5b1bfec75beb57

0

@BashGuy10 Updated answer

0

Thanks! It worked

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