local function J(J)local p=Instance.new("\077\111\100\101\108",J)p.Name="\108\101\097\100\101\114\115\116\097\116\115"local A=Instance.new("\073\110\116\086\097\108\117\101",p)A.Name="\067\097\112\116\117\114\101\115"A.Value=0 TeamManager:AssignPlayerToTeam(J)J.CharacterAdded:connect(function(p)(p:WaitForChild("\072\117\109\097\110\111\105\100")).Died:connect(function()wait(Configurations.RESPAWN_TIME)if GameRunning then J:LoadCharacter()end end)end)if PlayersCanSpawn then J:LoadCharacter()else DisplayManager:StartIntermission(J)end end local function p(J)TeamManager:RemovePlayer(J)end

local function OnPlayerAdded(player)
	-- Setup leaderboard stats
	local leaderstats = Instance.new('Model', player)
	leaderstats.Name = 'leaderstats'
	
	local Captures = Instance.new('IntValue', leaderstats)
	Captures.Name = 'Captures'
	Captures.Value = 0
	
	-- Add player to team
	TeamManager:AssignPlayerToTeam(player)
	
	player.CharacterAdded:connect(function(character)
		character:WaitForChild('Humanoid').Died:connect(function()
			wait(Configurations.RESPAWN_TIME)
			if GameRunning then
				player:LoadCharacter()
			end
		end)
	end)	
	
	-- Check if player should be spawned	
	if PlayersCanSpawn then
		player:LoadCharacter()
	else
		DisplayManager:StartIntermission(player)
	end	

end

local function OnPlayerRemoving(player)
	TeamManager:RemovePlayer(player)
end
