Value isn't resetting (but only sometimes, at random)?

My game has a 1v1 duel arena. I have 2 “zones” for players to stand in and when 2 players stand in it then it teleports them into a fighting arena, and when time runs out or one dies it resets for the next 2 people.

For whatever reason though, it registers people as being in the zone forever when they are not.

I have tried everything I can to fix this. I am not too sure what to do about it now

Heres my code

local zone = require(game.ServerScriptService.ZoneHandle.Zone)

local p1 = zone.new(script.Parent.p1)
local p2 = zone.new(script.Parent.p2)
local fight = zone.new(script.Parent.FightZone)

local gIA = script.Parent.gameIsActive

local p1player = nil
local p2player = nil
local count = 0
local countdownOn = false

local rs1
local rs2

local function getLivePlrs()
	local plrs = fight:getPlayers()
	local newArray = {}
	for i, v in pairs(plrs) do
		if v.Character.Humanoid.Health > 0 then
			table.insert(newArray, v)
		end
	end
	return newArray
end

local function reset()
	print('resetted')
	local plrs = getLivePlrs()
	print(plrs)
	for i, v in pairs(plrs) do
		v.Character:SetPrimaryPartCFrame(CFrame.new(16, 10, -10))
	end
	p1player = nil
	p2player = nil
	countdownOn = false
	count = 0
	gIA.Value = false
	script.Parent.BoardPart.SurfaceGui.Count.Text = tostring("Waiting for Players")
end

local function startCountdown()
	print("countdownStarted")
	countdownOn = true
	count = 20
	coroutine.wrap(function()
		while wait(1) do
			if countdownOn == true then
				print(count, countdownOn)
				count -= 1
				print(count, countdownOn)
				script.Parent.BoardPart.SurfaceGui.Count.Text = tostring(count)
				local plrs = getLivePlrs()
				if count <= 0 or #plrs <= 1 then
					reset()
					break
				end
			elseif countdownOn == false then
				script.Parent.BoardPart.SurfaceGui.Count.Text = tostring("Waiting for Players")
				print(countdownOn)
				break
			end
		end
	end)()
end

fight.playerEntered:Connect(function(plr)
	plr:WaitForChild("canTp").Value = false
end)

p1.playerEntered:Connect(function(plr)
	if plr then
		if plr.Character:FindFirstChildOfClass("ForceField") == nil then
			local safeField = Instance.new("ForceField")
			safeField.Parent = plr.Character
			safeField.Name = "SafeField"
			safeField.Visible = false
			pcall(function()
				plr.Character.Head.Shield.ImageLabel.ImageTransparency = 0
			end)
		end
		plr:WaitForChild("canTp").Value = false
	end

	rs1 = game:GetService("RunService").Heartbeat:Connect(function()
		if gIA.Value == false then
			if p1player == nil then
				p1player = plr.Name
				game:GetService("TweenService"):Create(script.Parent.p1.P1Slot.SelectionBox, TweenInfo.new(0.3), {Color3 = Color3.fromRGB(74, 255, 65)}):Play()
			end
		end
	end)
end)

p1.playerExited:Connect(function(plr)
	if plr then
		pcall(function()
			if plr.Character:FindFirstChildOfClass("ForceField") ~= nil then
				plr.Character:FindFirstChildOfClass("ForceField"):Remove()
			end
		end)
		pcall(function()
			plr.Character.Head.Shield.ImageLabel.ImageTransparency = 1
		end)
		plr:WaitForChild("canTp").Value = true
	end

	game:GetService("TweenService"):Create(script.Parent.p1.P1Slot.SelectionBox, TweenInfo.new(0.3), {Color3 = Color3.fromRGB(255, 99, 99)}):Play()

	rs1:Disconnect()

	p1player = nil
end)

p2.playerEntered:Connect(function(plr)
	if plr then
		if plr.Character:FindFirstChildOfClass("ForceField") == nil then
			local safeField = Instance.new("ForceField")
			safeField.Parent = plr.Character
			safeField.Name = "SafeField"
			safeField.Visible = false
			pcall(function()
				plr.Character.Head.Shield.ImageLabel.ImageTransparency = 0
			end)
		end
		plr:WaitForChild("canTp").Value = false
	end

	rs2 = game:GetService("RunService").Heartbeat:Connect(function()
		if gIA.Value == false then
			if p2player == nil then
				p2player = plr.Name
				game:GetService("TweenService"):Create(script.Parent.p2.P2Slot.SelectionBox, TweenInfo.new(0.3), {Color3 = Color3.fromRGB(74, 255, 65)}):Play()
			end
		end
	end)
end)

p2.playerExited:Connect(function(plr)
	if plr then
		pcall(function()
			if plr.Character:FindFirstChildOfClass("ForceField") ~= nil then
				plr.Character:FindFirstChildOfClass("ForceField"):Remove()
			end
		end)
		pcall(function()
			plr.Character.Head.Shield.ImageLabel.ImageTransparency = 1
		end)
		plr:WaitForChild("canTp").Value = true
	end

	game:GetService("TweenService"):Create(script.Parent.p2.P2Slot.SelectionBox, TweenInfo.new(0.3), {Color3 = Color3.fromRGB(255, 99, 99)}):Play()

	rs2:Disconnect()

	p2player = nil
end)
game:GetService("RunService").Heartbeat:Connect(function()
	if gIA.Value == false then
		if p1player ~= nil and p2player ~= nil then
			gIA.Value = true
			print(p1player, p2player)

			local work,nowork = pcall(function()
				game.Workspace:FindFirstChild(p1player):SetPrimaryPartCFrame(CFrame.new(script.Parent.p1TPPart.Position))
			end)

			if nowork then
				p1player = nil
				gIA.Value = false
				game:GetService("TweenService"):Create(script.Parent.p1.P1Slot.SelectionBox, TweenInfo.new(0.3), {Color3 = Color3.fromRGB(255, 99, 99)}):Play()
				print(nowork)
			end



			local work2,nowork2 = pcall(function()
				game.Workspace:FindFirstChild(p2player):SetPrimaryPartCFrame(CFrame.new(script.Parent.p2TPPart.Position))
			end)

			if nowork2 then
				p2player = nil
				gIA.Value = false
				game:GetService("TweenService"):Create(script.Parent.p2.P2Slot.SelectionBox, TweenInfo.new(0.3), {Color3 = Color3.fromRGB(255, 99, 99)}):Play()
				print(nowork2)
			end

			if work and work2 then
				startCountdown()
				print("worked")
			end

		end
	end
	
	if p1player ~= nil then
		if fight:findPlayer(game.Players:FindFirstChild(p1player)) == nil and p1:findPlayer(game.Players:FindFirstChild(p1player)) == nil then
			p1player = nil
		end
	end
	
	if p2player ~= nil then
		if fight:findPlayer(game.Players:FindFirstChild(p2player)) == nil and p2:findPlayer(game.Players:FindFirstChild(p2player)) == nil then
			p2player = nil
		end
	end
end)