Attempt to index nil debug

So I was making an animation for one of my tools then I got an error that said Players.NavenTheNoob.Backpack.Apple.LocalScript:9: attempt to index nil with ‘Stop’

I have no idea on how to fix this an I really need help!

This is the code:

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

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

Replace the ‘Unequipped’ block with this:

script.Parent.Unequipped:Connect(function()
	if animation ~= nil then
       animation:Stop()
    end
end)
1 Like

its fixed, thank you so much bro

1 Like