function findAllFlagStands(T)local B=T:children()for T=1,#B,1 do if B[T].className=="\077\111\100\101\108"or B[T].className=="\080\097\114\116"then findAllFlagStands(B[T])end if B[T].className=="\070\108\097\103\083\116\097\110\100"then table.insert(stands,B[T])end end end function hookUpListeners()for T=1,#stands,1 do stands[T].FlagCaptured:connect(onCaptureScored)end end function onPlayerEntered(T)if Fight_mode==true then local B=Instance.new("\073\110\116\086\097\108\117\101")B.Name="\108\101\097\100\101\114\115\116\097\116\115"local O=Instance.new("\073\110\116\086\097\108\117\101")O.Name="\067\097\112\116\117\114\101\115"O.Value=0 O.Parent=B while true do if T.Character~=nil then break end wait(5)end B.Parent=T else local B=Instance.new("\073\110\116\086\097\108\117\101")B.Name="\108\101\097\100\101\114\115\116\097\116\115"local O=Instance.new("\073\110\116\086\097\108\117\101")O.Name="\075\079\115"O.Value=0 local u=Instance.new("\073\110\116\086\097\108\117\101")u.Name="\087\105\112\101\111\117\116\115"u.Value=0 O.Parent=B u.Parent=B while true do if T.Character~=nil then break end wait(5)end local F=T.Character.Humanoid F.Died:connect(function()onHumanoidDied(F,T)end)T.Changed:connect(function(B)onPlayerRespawn(B,T)end)B.Parent=T end end function onCaptureScored(T)local B=T:findFirstChild("\108\101\097\100\101\114\115\116\097\116\115")if B==nil then return end local O=B:findFirstChild("\067\097\112\116\117\114\101\115")if O==nil then return end O.Value=O.Value+1 end findAllFlagStands(game.Workspace)hookUpListeners()if#stands>0 then CTF_mode=false end game.Players.ChildAdded:connect(onPlayerEntered)




function findAllFlagStands(root)
	local c = root:children()
	for i=1,#c do
		if (c[i].className == "Model" or c[i].className == "Part") then
			findAllFlagStands(c[i])
		end
		if (c[i].className == "FlagStand") then
			table.insert(stands, c[i])
		end
	end
end

function hookUpListeners()
	for i=1,#stands do
		stands[i].FlagCaptured:connect(onCaptureScored)
	end
end

function onPlayerEntered(newPlayer)

	if Fight_mode == true then

		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"

		local captures = Instance.new("IntValue")
		captures.Name = "Captures"
		captures.Value = 0


		captures.Parent = stats

		-- VERY UGLY HACK
		-- Will this leak threads?
		-- Is the problem even what I think it is (player arrived before character)?
		while true do
			if newPlayer.Character ~= nil then break end
			wait(5)
		end

		stats.Parent = newPlayer

	else

		local stats = Instance.new("IntValue")
		stats.Name = "leaderstats"

		local kills = Instance.new("IntValue")
		kills.Name = "KOs"
		kills.Value = 0

		local deaths = Instance.new("IntValue")
		deaths.Name = "Wipeouts"
		deaths.Value = 0

		kills.Parent = stats
		deaths.Parent = stats

		-- VERY UGLY HACK
		-- Will this leak threads?
		-- Is the problem even what I think it is (player arrived before character)?
		while true do
			if newPlayer.Character ~= nil then break end
			wait(5)
		end

		local humanoid = newPlayer.Character.Humanoid

		humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )

		-- start to listen for new humanoid
		newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )


		stats.Parent = newPlayer

	end

end


function onCaptureScored(player)

		local ls = player:findFirstChild("leaderstats")
		if ls == nil then return end
		local caps = ls:findFirstChild("Captures")
		if caps == nil then return end
		caps.Value = caps.Value + 1

end


findAllFlagStands(game.Workspace)
hookUpListeners()
if (#stands > 0) then CTF_mode = false end
game.Players.ChildAdded:connect(onPlayerEntered)



