Trouble with Flag Capturing Point

Hello all,
I am creating an FPS DDay game and I am currently making the flag capturing points. The player needs to stand near the flag for it to raise their own flag and once they have a flag, their team can spawn there. I have successfully created this but have run into an issue. This is that whenever a player dies in the checkpoint the value for people in the zone doesn’t change (number value). It is basically a cube that records when a player from the team enters the cube and exits the cube. It is just not recognising that the player has left the cube since they didn’t move back out through the cube. (I used the touched and touchended function). I was thinking that there might be a way to use a table or array to store players and then it will take there name out of the table when they leave or when they die. Ask any questions if this doesn’t make sense. Thanks :grinning:

This is the script used for changing the 2 values, red (when a red player is in zone) and blue (when a blue player is in zone).

local red = script.Parent.Red
local blue = script.Parent.Blue
local total = script.Parent.Total


--------------------------------- TOUCH STARTED

function onTouch(hit) 
local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
	if user ~= nil then 
		local plrTeam = user.Team
		if plrTeam == game.Teams.Allies and user.InCapture.Value == false and user.Character.Humanoid.Health ~= 0 then
			if user.Character.Humanoid.Health == 0 then
				user.InCapture.Value = false
				blue.Value = blue.Value - 1
			else
				user.InCapture.Value = true
				blue.Value = blue.Value + 1
				user.Character.Humanoid.Died:Connect(function()
					blue.Value = blue.Value - 1
				end)
			end
			user.InCapture.Value = true
			blue.Value = blue.Value + 1
		elseif plrTeam == game.Teams.Axis and user.InCapture.Value == false then
			if user.Character.Humanoid.Health == 0 then
				user.InCapture.Value = false
				red.Value = red.Value - 1
			else
				user.InCapture.Value = true
				red.Value = red.Value + 1
			end
		end
	end
end

--------------------------------- TOUCH ENDED

function touchended(hit)
	local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
	if user ~= nil then 
		local plrTeam = user.Team
		if plrTeam == game.Teams.Allies and user.InCapture.Value == true and user.Character.Humanoid.Health ~= 0 then
			user.InCapture.Value = false
			blue.Value = blue.Value - 1
		elseif plrTeam == game.Teams.Axis and user.InCapture.Value == true and user.Character.Humanoid.Health ~= 0 then
			user.InCapture.Value = false
			red.Value = red.Value - 1
		end
	end
end

script.Parent.TouchEnded:Connect(touchended)

script.Parent.Touched:connect(onTouch) 

Have another script for rising and lowering the flag aswell which works fine :grin: