Lives system not working

Hi there,

So I am having issues with my stock system. In the effort of debugging I feel like I’ve exhausted all my ideas for fixing it, and I need some help

I’m trying to make a lives system but the died events on both players only work once and then break, even without a disconnect anywhere. Anyone know what’s up?

function Start()
	started = true
	print("Started")

	local p = game.Players:GetPlayers()
	local Spawns = workspace:WaitForChild("Map"):WaitForChild("Spawns")

	local p1value = Instance.new("StringValue", p[1])
	local p2value = Instance.new("StringValue", p[2])

	p1value.Name = "PlayerNumber"
	p2value.Name = "PlayerNumber"

	p1value.Value = "1"
	p2value.Value = "2"

	p[1]:SetAttribute('Stock', 3)
	p[2]:SetAttribute('Stock', 3)

	local p1stock, p2stock = p[1]:GetAttribute('Stock'), p[2]:GetAttribute('Stock')

	ReplicatedStorage.StockChange:FireAllClients(p1stock, p[1], "Player1")
	ReplicatedStorage.StockChange:FireAllClients(p2stock, p[2], "Player2")

	p[1].Character.HumanoidRootPart.CFrame = Spawns.Spawn1.CFrame + Vector3.new(0, 7, 0)
	p[2].Character.HumanoidRootPart.CFrame = Spawns.Spawn2.CFrame + Vector3.new(0, 7, 0)

	print("Finished inital start sequence")

	for i, plr in pairs(game.Players:GetPlayers()) do
		plr.PlayerGui.StartGUI:Destroy()
	end 

	local connections = {}

	task.spawn(function()
		connections[1] = p[1].Character.Humanoid.Died:Connect(function()
			if p[1]:GetAttribute('Stock') > 0 then
				p[1]:SetAttribute('Stock', p1stock - 1)
				p1stock = p[1]:GetAttribute('Stock')

				ReplicatedStorage.StockChange:FireAllClients(p1stock, p[1], "Player1")
			else
				if AlreadyWon == true then
					return
				else
					AlreadyWon = true
					EndGame(p[2])
				end
			end
		end)
	end)
	
	task.spawn(function()
		connections[2] = p[2].Character.Humanoid.Died:Connect(function()
			if p[2]:GetAttribute('Stock') > 0 then
				p[2]:SetAttribute('Stock', p2stock - 1)
				p1stock = p[2]:GetAttribute('Stock')

				ReplicatedStorage.StockChange:FireAllClients(p1stock, p[2], "Player2")
			else
				if p[2]:GetAttribute('Stock') == 0 then
					if AlreadyWon == true then
						return
					else
						AlreadyWon = true
						EndGame(p[1])
					end
				end
			end
		end)
	end)

	MatchmakingService:StartGame(MatchmakingService:GetCurrentGameCode())

	print("Game started B)")

	table.insert(t1, p[1])
	t1[1] = "player1"
	table.insert(t2, p[2])
	t2[1] = "player2"
end

Your .Died connection will only fire a single time since it is bound to the humanoid. Upon respawning the player is given a new humanoid, so you have to redefine a connection to the new one.

Edit: I ended up just rewriting the system, its now much more readable and can be much easier debugged