My tool Click Animation does not work when cloned to Backpack

Hello, This Is my first post on the DevForum

So I recently started watching a tutorial how to create a game, It is going well but I recently ran into a roadblock involving my Tool Animation.

Basically, When you click the tool I created, it plays an animation, But when the Tool is cloned into backpack from the shop, the animation does not work. The rest of the functions work, but the animation doesn’t. It works fine if I were to put it in the starter pack, But I do not know why it does not work when cloned. If you know the solution, I would appreciate it. Thanks.

can you write the script that is running the animation ?

local Pan = script.Parent

local debounce = false

local tool = script.Parent
local anim = Instance.new(“Animation”)
anim.AnimationId = ‘rbxassetid://6932197225’
local debounce = false
local track

tool.Activated:Connect(function()
if debounce == false then
debounce = true
track = script.Parent.Parent.Humanoid.Animator:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = false
track:Play()

	wait(1) -- cooldown
	debounce = false
end

end)

	I dont know how to make the little script box lol

The Scripts Are Connected, So this Activates the tool and gives points and the other script activates the animation

local Cooldown = false

local player = game.Players.LocalPlayer

local DeB = false

script.Parent.Activated:Connect(function()
if Cooldown == false then
Cooldown = true

game.Workspace.MainEvent.AddSwings:FireServer()
	script.Parent.Enabled = false
	wait(1)
	script.Parent.Enabled = true
	
	Cooldown = false
	
end

end)

Is this script in StarterGUI? And is it a local script?

No, it is in a tools are in replicated storage, so i have a shop system that when you have enough currency, the tool is cloned and parented to the backpack, my problem is that the animation for cloned tool does not work when clicked. It works fine if i were to put it in the starter pack. And The script that runs the animation is a regular script

You don’t have to create a new animation track every time the tool is activated. You should also reference the animator through the player’s character since when the tool first exists/is first parented to the backpack, it’s looking for an animator inside of the player/the player’s backpack. You also have 3 debounces, you only need 1.

local players = game:GetService('Players')
local localPlayer = players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild('Humanoid')
local animator = humanoid:FindFirstChild('Animator')

track = animator:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = false

local debounce = false

tool.Activated:Connect(function()
	if debounce == false then
		debounce = true
		track:Play()
		wait(1)
		debounce = false
	end
end)

You didn’t reference the tool. There isn’t a variable for it.

Yeah, I was just fixing the hierarchy.

Alright, Thank a lot for the help