Need Help With CharacterAdded

Making a thing in Roblox where you hold E on a part and you get an item, upon equipping the item a holding animation plays. Problem is that the CharacterAdded never runs when parented to the players backpack. Any idea of what is going on?

local tool = script.Parent
local isSweeping = true

local Player = game.Players.LocalPlayer

Player.CharacterAdded:Connect(function(character)
	local Humanoid = character:WaitForChild("Humanoid")
	local Holding = Humanoid:LoadAnimation(script:WaitForChild("HoldingAnim"))
	local Sweeping = Humanoid:LoadAnimation(script:WaitForChild("SweepingAnim"))

	tool.Equipped:Connect(function()
		Holding:Play()

		tool.Unequipped:Connect(function()
			Holding:Stop()

			tool.Activated:Connect(function()

				game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

				if isSweeping then
					isSweeping = false
					Sweeping:Play()
					task.wait(1.2)
					isSweeping = true

					game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
				end
			end)
		end)
	end)
end)

Where did you put the script at?

In a local script in the tool, is that why its not working?

Instead of using Player.CharacterAdded, just wait for the character. The CharacterAdded event will never fire in that script because the script is added after the character is added because the script is inside a tool inside of the player’s backpack (which is placed there after the character spawns)

It would instead look like this:

local tool = script.Parent
local isSweeping = true

local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = character:WaitForChild("Humanoid")
local Holding = Humanoid:LoadAnimation(script:WaitForChild("HoldingAnim"))
local Sweeping = Humanoid:LoadAnimation(script:WaitForChild("SweepingAnim"))

tool.Equipped:Connect(function()
	Holding:Play()

	tool.Unequipped:Connect(function()
		Holding:Stop()

		tool.Activated:Connect(function()

			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

			if isSweeping then
				isSweeping = false
				Sweeping:Play()
				task.wait(1.2)
				isSweeping = true

				game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
			end
		end)
	end)
end)

It does load and play the animation, problem is if the player dies and respawns, it does this error.

Cannot load the AnimationClipProvider Service.