Why Is My Animation For My Tool Breaking When The Tool Is Cloned Into The Players Backpack?

I Made A Tool In My Game And It Has Animations But I Also Have A Purchase Button For Ingame Currency But When The Tool Is Cloned To The Players Backpack I Get An Error In The Output Saying

Animation is not a valid member of LocalScript

And I Don’t Know Why Because It Works Fine When I Put It In Starterpack Here Is The Local Script:

local Tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local character = game.Workspace:WaitForChild(player.Name)
local Humanoid = character:WaitForChild('Humanoid')
animation=Humanoid.Animator:LoadAnimation(script.Animation) -- This Is Where The Error Happends
local uses = 0
local debounce = false
local sound1 = game.ReplicatedStorage.Sounds.EatingSound1
local sound2 = game.ReplicatedStorage.Sounds.EatingSoundDone2


Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if not debounce then
			if uses == 4 then
				local sound2Clone = sound2:Clone()
				sound2Clone.Parent = script.Parent
				sound2Clone:Play()
				script.Parent.Parent:Destroy()
			else
				local sound1Clone = sound1:Clone()
				sound1Clone.Parent = script.Parent
				sound1Clone:Play()
				debounce = true
				animation:Play()
				player.Character.Humanoid.Health += 15
				uses += 1
				sound1Clone:Destroy()
				debounce = false
			end
		end
	end)
end)

Thanks

Hi, where are you storing the tool before it is cloned?

In A Folder In Replicated Storage

try

local animation = Humanoid.Animator:LoadAnimation(script:WaitForChild("Animation"))
2 Likes

it is also good practice to use

local character = player.Character or player:CharacterAdded:Wait()

since an object in workspace can have the same name as a player

2 Likes