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