Why wont my trailscript work

game.Players.PlayerAdded:Connect(function(player)
	local EquippedTrail = Instance.new("StringValue")
	EquippedTrail.Name = "EquippedTrail"
	EquippedTrail.Parent = player

	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			player.CharacterAdded:Connect(function()
				if EquippedTrail.Value ~= nil then
					local TrailClone = game.ServerStorage:WaitForChild("Trails"):FindFirstChild(EquippedTrail.Value):Clone()
					TrailClone.Name = "Trail"
					TrailClone.Parent = player.Character
				end             
			end)
		end)
	end)

	EquippedTrail.Changed:Connect(function()
		if EquippedTrail.Value ~= nil and game.ServerStorage:WaitForChild("Trails"):FindFirstChild(EquippedTrail.Value) then
			if player.Character:FindFirstChild("Trail") then
				player.Character.Trail:Destroy()
			end

			local TrailClone = game.ServerStorage:WaitForChild("Trails"):FindFirstChild(EquippedTrail.Value):Clone()
			TrailClone.Name = "Trail"
			TrailClone.Parent = player.Character
		end
	end)
end)

game.ReplicatedStorage.EquipTrail.OnServerEvent:Connect(function(player, TrailName)
	if player:FindFirstChild("EquippedTrail") then
		player.EquippedTrail.Value = TrailName
	end
end)

game.ReplicatedStorage.UnequipTrail.OnServerEvent:Connect(function(player)
	if player.Character:FindFirstChild("Trail") then
		player.Character.Trail:Destroy()
	end

	if player:FindFirstChild("EquippedTrail") then
		player.EquippedTrail.Value = ""
	end
end)

it doesnt work

you’re binding CharacterAdded, Died, and then CharacterAdded

you don’t want to do this, as it doesnt do anything the first death, but then every death after it, its binding another character added event

We do this with humanoid in character added because every character’s humanoid is different, and we have to re-bind them

This results in no trails for the first character,
after you die, the next character has one trail
after you die, the next character has two trails
after you die, the next character has three trails
after you die, the next character has four trails

long story short turn this

player.CharacterAdded:Connect(function(character)
	character.Humanoid.Died:Connect(function()
		--in this case you don't need to bind anything to Died
		--if you need to later then put your connection here
	end)
	if EquippedTrail.Value ~= nil then
		local TrailClone = game.ServerStorage:WaitForChild("Trails"):FindFirstChild(EquippedTrail.Value):Clone()
		TrailClone.Name = "Trail"
		TrailClone.Parent = player.Character
	end        
end)

when i die, the trail unequips, and i have to equip it again manually

also, for trails to work they need to have an Attachment1 and Attachment0, and you don’t appear to be setting Attachment0 and Attachment1

how do i change the script so it works?

you need to make an attachment zero and attachment one in the character’s humanoid root part (or torso) and set the trail’s attachment zero and attachment one to it