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

Cannot stop animation after unequipped tool?

Asked by
BashGuy10 384 Moderation Voter
5 years ago

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

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)
0
0
Also here's my set up of the gun: https://gyazo.com/2c72b473fe697ae71c5b1bfec75beb57 BashGuy10 384 — 5y
0
@BashGuy10 Updated answer DanzLua 2879 — 5y
0
Thanks! It worked BashGuy10 384 — 5y
Ad

Answer this question