Loadanimation requires the humanoid object after respawning after death

so for some reason this is happening even by loading the animation with a humanoid and i dont understand why

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local combo = 0
local dmg = script.Parent:WaitForChild("HitBoxPart"):WaitForChild("Damage")
local db = false
local animation = script.Animation
local animtrack = humanoid:LoadAnimation(script:WaitForChild("Animation"))
local activated = false
local swing1 = script.Swing1
local swing2 = script.Swing2
local swing3 = script.Swing3
local swing1t = humanoid:LoadAnimation(script.Swing1)
local swing2t = humanoid:LoadAnimation(script.Swing2)
local swing3t = humanoid:LoadAnimation(script.Swing3)
local combo = 0
local db = false
local animation = script.Animation
local animtrack = humanoid:LoadAnimation(script.Animation)
animtrack.Priority = Enum.AnimationPriority.Action
	

script.Parent.Equipped:connect(function()
	activated = true
	if activated then
		animtrack:play()
	end
end)

script.Parent.Activated:Connect(function()
	if db == false then
		db = true
		combo += 1
		if combo == 1 then
			
			humanoid.WalkSpeed = 6
			humanoid.JumpPower = 0
			
			swing1t:Play()
			script.Parent.Handle.Trail.Enabled = true
			dmg.Disabled = false
			task.wait(1.03)
			dmg.Disabled = true
			script.Parent.Handle.Trail.Enabled = false
			db = false
			task.wait(0.6)
			humanoid.WalkSpeed = 9
			humanoid.JumpPower = 50
			return
		elseif combo == 2 then
			print("ok")
			db = true

			humanoid.WalkSpeed = 6
			humanoid.JumpPower = 0
			swing2t:Play()
			script.Parent.Handle.Trail.Enabled = true
			dmg.Disabled = false
			task.wait(0.46)
			dmg.Disabled = true
			script.Parent.Handle.Trail.Enabled = false
			db = false
			task.wait(0.6)
			humanoid.WalkSpeed = 9
			humanoid.JumpPower = 50
			return
		elseif combo == 3 then

			db = true

			humanoid.WalkSpeed = 6
			humanoid.JumpPower = 0
			swing3t:Play()
			script.Parent.Handle.Trail.Enabled = true
			dmg.Disabled = false
			task.wait(1.33)
			dmg.Disabled = true
			script.Parent.Handle.Trail.Enabled = false
			combo = 0
			task.wait(0.6)
			humanoid.WalkSpeed = 9
			humanoid.JumpPower = 50
			db = false
			return
		else
			
		end
		task.wait(2)
		db = false
	end
end)

Move the script to StarterCharacterScripts.

the thing is that its a sword and it wont work if i do

local tool = player.Backpack.NameOfTool

how do i get player in startercharacterscripts

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		local animator = Instance.new("Animator")
		animator.Parent = humanoid
	end)
end)

Try this instead, place this inside ServerScriptService.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local combo = 0
local dmg = script.Parent:WaitForChild("HitBoxPart"):WaitForChild("Damage")
local db = false
local animation = script.Animation
local animtrack = animator:LoadAnimation(script:WaitForChild("Animation"))
local activated = false
local swing1 = script.Swing1
local swing2 = script.Swing2
local swing3 = script.Swing3
local swing1t = animator:LoadAnimation(script.Swing1)
local swing2t = animator:LoadAnimation(script.Swing2)
local swing3t = animator:LoadAnimation(script.Swing3)
local combo = 0
local db = false
local animation = script.Animation
local animtrack = animator:LoadAnimation(script.Animation)
animtrack.Priority = Enum.AnimationPriority.Action


script.Parent.Equipped:connect(function()
	activated = true
	if activated then
		animtrack:play()
	end
end)

script.Parent.Activated:Connect(function()
	if db == false then
		db = true
		combo += 1
		if combo == 1 then

			humanoid.WalkSpeed = 6
			humanoid.JumpPower = 0

			swing1t:Play()
			script.Parent.Handle.Trail.Enabled = true
			dmg.Disabled = false
			task.wait(1.03)
			dmg.Disabled = true
			script.Parent.Handle.Trail.Enabled = false
			db = false
			task.wait(0.6)
			humanoid.WalkSpeed = 9
			humanoid.JumpPower = 50
			return
		elseif combo == 2 then
			print("ok")
			db = true

			humanoid.WalkSpeed = 6
			humanoid.JumpPower = 0
			swing2t:Play()
			script.Parent.Handle.Trail.Enabled = true
			dmg.Disabled = false
			task.wait(0.46)
			dmg.Disabled = true
			script.Parent.Handle.Trail.Enabled = false
			db = false
			task.wait(0.6)
			humanoid.WalkSpeed = 9
			humanoid.JumpPower = 50
			return
		elseif combo == 3 then

			db = true

			humanoid.WalkSpeed = 6
			humanoid.JumpPower = 0
			swing3t:Play()
			script.Parent.Handle.Trail.Enabled = true
			dmg.Disabled = false
			task.wait(1.33)
			dmg.Disabled = true
			script.Parent.Handle.Trail.Enabled = false
			combo = 0
			task.wait(0.6)
			humanoid.WalkSpeed = 9
			humanoid.JumpPower = 50
			db = false
			return
		else

		end
		task.wait(2)
		db = false
	end
end)

Then use the Animator instance created on the server to load the animations locally.

i move this into serverscript or keep it in tool

The longer script stays inside the tool like before.

what does this do?