Gun animation won't work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? - I’m trying to make a gun animation when you hold the tool, to replace the default one.

  2. What is the issue? - The script won’t work, there is already an animation.

  3. What solutions have you tried so far? I’ve tried the output and even YouTube videos, still can’t find the problem.

local anims = {script.Parent.HoldAnim, script.Parent.ShootAnim}
local loadedAnims = {}
local tool = script.Parent
local animator
tool.Equipped:Connect(function(mouse)
	animator = plr.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
	loadedAnims[1] = animator:LoadAnimation(anims[1])
	loadedAnims[1]:Play()
end)

tool.Unequipped:Connect(function()
	loadedAnims[1]:Stop()
-- I know the ShootAnim isn't written yet, I just need to find the problem for the HoldAnim first.
end)

Any help?

instead of
loadedAnims[1] = animator:LoadAnimation(anims[1])
try this
table.insert(loadedAnims,1,anims[1])

that’s useless, it does the same thing

animator is not in humanoid by default, you must create one.

local anims = {script.Parent.HoldAnim, script.Parent.ShootAnim}
local loadedAnims = {}
local tool = script.Parent
local animator
tool.Equipped:Connect(function(mouse)
	local animator
        if not plr.Chracter.Humanoid:FindFirstChildOfClass("Animator") then
              animator = Instance.new("Animator", plr.Character.Humanoid)
else
            animator = plr.Character.Humanoid.Animator -- doing because it would create a new animator every time tool is equipped        
end
	loadedAnims[1] = animator:LoadAnimation(anims[1])
	loadedAnims[1]:Play()
end)

tool.Unequipped:Connect(function()
	loadedAnims[1]:Stop()
        --- just do shootanim:Play(). It automatically comes back to hold aslong as the hold keyframe is at the end of the animation. No need for anim:Stop()
end)

Edited the script, and it’s good now. Thanks to everyone who helped. :))

What was the problem though, did you find it?

Yeah, I did. Just made a separate script for the shooting animation, instead of making a table, and it works fine.

Oh. That’s weird, because usually I use a table and it’s just fine.