-- Local Functions

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
